Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Code fixes | 28 comments | Create New Account
Click here to return to the 'Code fixes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Code fixes
Authored by: Kalak on Apr 22, '10 12:55:37PM
Since I have gnu tools from fink installed first in my path, I need to change the script to work with absolute paths for programs, and I've added a patch(Now I just need to convert this to use gnu tools to run on my linux boxes.)

Another tip to add is to really remove files immediately, use a backslash before "rm", so "\rm"

--- .bash.trash.sh 2010-04-22 15:51:40.000000000 -0400
+++ bash.trash.sh 2010-04-22 15:47:06.000000000 -0400
@@ -13 +13 @@
- command /bin/rm -i "$@"
+ command rm -i "$@"
@@ -20 +20 @@
- local HOME_DEVICE="$(/usr/bin/stat -f %Sd "$HOME")"
+ local HOME_DEVICE="$(stat -f %Sd "$HOME")"
@@ -31 +31 @@
- local DEVICE="$(/usr/bin/stat -f %Sd "$F")"
+ local DEVICE="$(stat -f %Sd "$F")"
@@ -46 +46 @@
- command /bin/rm -f "${TRASHCAN}"
+ command rm -f "${TRASHCAN}"
@@ -49 +49 @@
- echo "$TRASHCAN is inaccessible at this time." | /usr/bin/sed 's;'"$HOME"';~;g' 1>&2
+ echo "$TRASHCAN is inaccessible at this time." | sed 's;'"$HOME"';~;g' 1>&2
@@ -61 +61 @@
- if ! /bin/mv -vn "$F" "${TRASHCAN}/${FinT}"
+ if ! mv -vn "$F" "${TRASHCAN}/${FinT}"
@@ -68,2 +68,2 @@
- local TRASHSIZE="$(/usr/bin/du -hs "${TRASHCAN}" 2>/dev/null | cut -f 1)"
- local TRASHCANloc="$(dirname "$TRASHCAN" | /usr/bin/sed 's;^/Volumes/\(.*\)/.Trashes;\1;g' | /usr/bin/sed 's;'"$HOME"';~;g' | /usr/bin/sed 's;^/.Trashes;/;g')"
+ local TRASHSIZE="$(du -hs "${TRASHCAN}" 2>/dev/null | cut -f 1)"
+ local TRASHCANloc="$(dirname "$TRASHCAN" | sed 's;^/Volumes/\(.*\)/.Trashes;\1;g' | sed 's;'"$HOME"';~;g' | sed 's;^/.Trashes;/;g')"
@@ -78 +78 @@
- local MOUNTS=( $(mount | /usr/bin/sed -n 's:/dev/.* on \(.*\) (.*):\1:p') )
+ local MOUNTS=( $(mount | sed -n 's:/dev/.* on \(.*\) (.*):\1:p') )
@@ -84 +84 @@
- TRASH_SIZE="$( (for i in "${TRASHCANs[@]}"; do /bin/ls "$i"/; done) 2>/dev/null | wc -w)"
+ TRASH_SIZE="$( (for i in "${TRASHCANs[@]}"; do ls "$i"/; done) 2>/dev/null | wc -w)"
---
--
Kalak
I am, and always will be, an Idiot.
---
--
Kalak
I am, and always will be, an Idiot.
Edited on Apr 22, '10 12:56:45PM by Kalak


[ Reply to This | # ]
Code fixes
Authored by: GaelicWizard on Apr 22, '10 04:52:20PM

Just out of curiosity, why do you have broken tools in your path?

Serious question, I'm not just trying to flame/troll/whatever.



[ Reply to This | # ]
Code fixes
Authored by: Kalak on Apr 27, '10 07:44:05AM

They're not broken, they just work differently. The GNU tools installed by fink are what I'm more used to using from my linux experience starting when OSX was Nextstep, and I only wished I could afford the RAM to run it (early '90s). Some would ask the question of why OSX tools are "broken" because they use the BSD syntax. I see it as "you say tomato I say tomato" issue (ok, that doesn't type well). I've worked on both, but use the GNU tool much more than BSD tools. That's why I knew what the issue of why the script didn't work as posted on my box.

The changes will make sure the script works on any box, even with fink or macports installed, regardless of the user's PATH. The absolute path just makes sure your script uses the Apple installed utils, so you can focus on just supporting them, and will avoid a FAQ on why the script doesn't work.

---
--
Kalak
I am, and always will be, an Idiot.



[ Reply to This | # ]
Code fixes
Authored by: rahulbenegal on Apr 22, '10 11:17:41PM

Could you upload the modified code to gist and link it. I applied the patch but it gave failures.

Also, if someone converts this to a shell-script, please post a link. Thanks.



[ Reply to This | # ]
Code fixes (fixed for real this time)
Authored by: Kalak on Apr 29, '10 12:56:25PM
I reversed the order of the files when I created the diff. To use, save the hint's code to a file. I used .bash.trash.sh so it won't show in the finder, etc. Then run the following (which points to an updated diff):
curl http://iddl.vt.edu/~jackie/bash.trash.diff | patch -p0 .bash.trash.sh
you then source .bash.trash.sh with the line:
. ~/.bash_trash
try it, if you're happy, then remove .bash.trash.sh.orig---
--
Kalak
I am, and always will be, an Idiot.
---
--
Kalak
I am, and always will be, an Idiot.
Edited on Apr 29, '10 12:57:31PM by Kalak


[ Reply to This | # ]