aboutsummaryrefslogtreecommitdiff
path: root/sel
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsel99
1 files changed, 99 insertions, 0 deletions
diff --git a/sel b/sel
new file mode 100755
index 0000000..fd8020f
--- /dev/null
+++ b/sel
@@ -0,0 +1,99 @@
1#!/bin/sh
2
3# Allow bulk operations on a list of selected files.
4# Usage: sel [command]
5# If no command is specified, shows the list of selected files
6# Commands:
7# add [files|dirs|all]: add files to selection
8# clear: clear selection
9# cp: copy to current dir, possbily after editing filenames
10# edit: open selection in editor
11# mv: move to current dir, possbily after editing filenames
12# rm: remove selected files and clear selection
13
14# Requires: dmenu (or similar), trashrm (optional)
15
16# TODO: add possibility of specifying file.
17# TODO 2: The usage of paste(1) is a bit of a hack, and for example it does
18# not work if filenames contain tab characters. Fix this.
19
20file="$XDG_DATA_HOME/selectedfiles"
21menu=${MENU:-dmenu}
22editor=${EDITOR:-vi}
23rm=trashrm # replace with rm -r if you don't use trashrm
24
25clear() {
26 cat /dev/null > "$file"
27}
28
29cphere() {
30 file2=$(mktemp)
31 sed 's/^.*\///' "$file" > "$file2"
32 $editor "$file2"
33 paste "$file" "$file2" | while read f; do
34 fold=$(echo "$f" | sed 's/\t.*//')
35 fnew=$(echo "$f" | sed 's/.*\t//')
36 cp -R "$fold" ./"$fnew"
37 done
38 clear
39}
40
41remove() {
42 while read f; do
43 $rm "$f"
44 done < "$file"
45}
46
47if [ -z "$1" ]; then
48 cat "$file"
49else
50case "$1" in
51 add)
52 if [ -z "$2" ]; then
53 dmenu-filepicker >> "$file"
54 else
55 case "$2" in
56 files)
57 ls | while read f; do
58 [ -f "$f" ] && echo "$PWD/$f" >> "$file"
59 done
60 ;;
61 dirs)
62 ls | while read f; do
63 [ -d "$f" ] && echo "$PWD/$f" >> "$file"
64 done
65 ;;
66 all)
67 ls | while read f; do
68 echo "$PWD/$f" >> "$file"
69 done
70 ;;
71 *)
72 echo "$2: not a valid option"
73 ;;
74 esac
75 fi
76 sort -u -o "$file" "$file"
77 ;;
78 clear)
79 clear
80 ;;
81 cp)
82 cphere
83 ;;
84 edit)
85 $editor "$file"
86 ;;
87 mv)
88 cphere
89 remove
90 ;;
91 rm)
92 remove
93 clear
94 ;;
95 *)
96 echo "$1: not a valid sel command"
97 ;;
98esac
99fi

Generated with cgit - Back to sebastiano.tronto.net