summarylogtreecommitdiffstats
path: root/link.patch
blob: 1ce1b97d4a58ca46e358a367383ea14878d4c68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--- bashtrash/trash	2015-09-16 12:21:08.127829933 +0200
+++ bashtrash/trash	2015-09-16 12:19:58.623599106 +0200
@@ -40,7 +40,7 @@
   exit 1
 }
 
-# sed script to encode filenames
+#%fold sed script to encode filenames
 
 sedscript='s/ /%20/g
 s/!/%21/g
@@ -70,13 +70,14 @@
 s/|/%7c/g
 s/}/%7d/g
 s/~/%7e/g
-s/	/%09/g'
+s/	/%09/g' #%endfold
 
 function url_encode {
   echo $1 |sed -e "$sedscript"
 }
 
 function get_trashdir {
+  if [ "x$trashhome" = "x" ]  ; then
   mounts=`awk '{ print $2 }' /proc/mounts`
   base=/
 
@@ -106,6 +107,7 @@
       base=$HOME
     fi
   fi
+  else base="$HOME"; fi
 
   if [ "$base" == "$HOME" ]; then
     base=$XDG_DATA_HOME
@@ -121,7 +123,8 @@
 function can_trash {
   filename="$1"
 
-  if [ ! -e "$filename" ]; then
+
+  if [ ! -e "$filename" ] && [ ! -L "$filename" ] ; then
     if [ "$interactive" != "force" ]; then
       echo "${progname}: cannot move \`$filename' to trash: No such file or directory" 1>&2
     fi
@@ -129,7 +132,7 @@
   else
 
     type="file"
-    if [ -d "$filename" ]; then
+    if [ -d "$filename" ]  && [ ! -L "$filename" ] ; then
       type="directory"
     fi
 
@@ -173,20 +176,21 @@
   init_trashdir "$trashdir"
 
   trashname="${filename##*/}"
-  origname="${trashname%%.*}"
-  if [ -z "${origname}" ]; then
-      origname="dotfile"
-  fi
-  ext=".${trashname##*.}"
-  if [ "$ext" == ".$trashname" ]; then
-    ext=""
-  fi
+#%fold guido   origname="${trashname%%.*}"
+#   if [ -z "${origname}" ]; then
+#       origname="dotfile"
+#   fi
+#  ext=".${trashname##*.}"
+#  if [ "$ext" == ".$trashname" ]; then
+#    ext=""
+#%endfold  fi
 
   # Use -u (unsafe) option because we cannot mv a directory into a
   # file.  This is technically "unsafe" but mv will ask for
   # confirmation when overwriting.
 
-  deletedfile=$(mktemp -u "${trashdir}/files/${origname}_XXXXXXXX" )$ext
+  # deletedfile=$(mktemp -u "${trashdir}/files/${origname}_XXXXXXXX" )$ext
+  deletedfile=$(mktemp -u "${trashdir}/files/`date +"%y-%m-%d-%H:%M:%S"`-${trashname}_XXXXXXXX")
   deletedbase=$( basename "${deletedfile}" )
   deletedinfo="$trashdir/info/${deletedbase}.trashinfo"
 
@@ -233,7 +237,7 @@
 interactive=never
 filename=
 
-while getopts hvirRf arg; do
+while getopts hvirRft arg; do
     case $arg in
 	h) show_usage;
 	    exit 1
@@ -246,6 +250,8 @@
 	    ;;
 	f) interactive=force
 	    ;;
+	t) trashhome=yes
+	    ;;
 	[?]) try_help
 	    exit 1
 	    ;;
@@ -258,7 +264,13 @@
 
   # get full pathname of file
 
+  link=$(echo ${f} |sed -e "s/\/$//g")
+  if [ -L "${link}" ] ; 
+  then 
+    filename="$PWD/${link}" 
+  else 
   filename="$(readlink -f "${f}")"
+  fi
 
   yes=`can_trash "$filename"`
   if [ "$yes" != "0" ]; then