Added -f and -r options for compatability with rm.
Minor code cleanup.
This commit is contained in:
parent
36fca41a17
commit
d53465c5b7
17
trash
17
trash
@ -15,7 +15,7 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
version="0.3.4 \$Id: trash 2011/03/17 14:56:07 GMT rr@dwaible $"
|
version="0.3.6 \$Id: trash 2011/03/17 15:03:22 GMT rr@dwaible $"
|
||||||
|
|
||||||
function show_usage {
|
function show_usage {
|
||||||
cat << EOU
|
cat << EOU
|
||||||
@ -28,6 +28,8 @@ Options:
|
|||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbose explain what is being done
|
-v, --verbose explain what is being done
|
||||||
-i, --interactive prompt before moving every file
|
-i, --interactive prompt before moving every file
|
||||||
|
-r, -R, --recursive ignored (for compatability with rm)
|
||||||
|
-f, --force ignore non-existent files, never prompt
|
||||||
EOU
|
EOU
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ function try_help {
|
|||||||
|
|
||||||
# Option handling
|
# Option handling
|
||||||
|
|
||||||
if ! options=$(getopt -o hvi -l "help,verbose,interactive::,version" -n "$0" -- $@)
|
if ! options=$(getopt -o hvirRf -l "help,verbose,interactive::,version,recursive,force" -n "$0" -- $@)
|
||||||
then
|
then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -72,7 +74,9 @@ case $1 in
|
|||||||
fi
|
fi
|
||||||
interactive=$arg
|
interactive=$arg
|
||||||
;;
|
;;
|
||||||
--version) echo "$0 $version" 1>&2;;
|
--version) echo "$0 $version" 1>&2 ;;
|
||||||
|
-r|-R|--recursive) ;;
|
||||||
|
-f|--force) interactive=force ;;
|
||||||
(--) shift; break;;
|
(--) shift; break;;
|
||||||
(-*) echo "$0: invalid option -- '$1'" 1>&2 ; try_help ; exit 1 ;;
|
(-*) echo "$0: invalid option -- '$1'" 1>&2 ; try_help ; exit 1 ;;
|
||||||
(*) break;;
|
(*) break;;
|
||||||
@ -170,9 +174,10 @@ function can_trash {
|
|||||||
filename=$1
|
filename=$1
|
||||||
|
|
||||||
if [ ! -e "$filename" ]; then
|
if [ ! -e "$filename" ]; then
|
||||||
echo "$0: cannot move \`$filename' to trash: No such file or directory" 1>&2
|
if [ "$interactive" != "force" ]; then
|
||||||
|
echo "$0: cannot move \`$filename' to trash: No such file or directory" 1>&2
|
||||||
|
fi
|
||||||
echo 0
|
echo 0
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
type="file"
|
type="file"
|
||||||
@ -181,7 +186,7 @@ function can_trash {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
case $interactive in
|
case $interactive in
|
||||||
never) echo 1 ;;
|
never|force) echo 1 ;;
|
||||||
always)
|
always)
|
||||||
read -p "$0: move ${type} '${filename}' to trash?" yn
|
read -p "$0: move ${type} '${filename}' to trash?" yn
|
||||||
if [[ "$yn" =~ ^[yY]$ ]]; then
|
if [[ "$yn" =~ ^[yY]$ ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user