aboutsummaryrefslogtreecommitdiff
path: root/sel
diff options
context:
space:
mode:
Diffstat (limited to 'sel')
-rwxr-xr-xsel65
1 files changed, 34 insertions, 31 deletions
diff --git a/sel b/sel
index f5fa058..5d057e8 100755
--- a/sel
+++ b/sel
@@ -1,10 +1,11 @@
1#!/bin/sh 1#!/bin/sh
2 2
3# Allow bulk operations on a list of selected files. 3# Allow bulk operations on a list of selected files.
4# Usage: sel [command] 4# Usage: sel [-m menu] [command]
5# If no command is specified, shows the list of selected files 5# If no command is specified, shows the list of selected files
6# Commands: 6# Commands:
7# add [files|dirs|all]: add files to selection 7# add [files...]: add files to selection
8# addall: add all files in the current folder to selection
8# clear: clear selection 9# clear: clear selection
9# cp: copy to current dir, possbily after editing filenames 10# cp: copy to current dir, possbily after editing filenames
10# edit: open selection in editor 11# edit: open selection in editor
@@ -12,44 +13,44 @@
12# open: open files using open-file 13# open: open files using open-file
13# rm: remove selected files and clear selection 14# rm: remove selected files and clear selection
14 15
15# Requires: dmenu (or similar), trashrm (optional), open-file (for open only) 16# Requires: dmenu (or similar), trash (optional), open-file (for open only)
16 17
17# TODO: add possibility of specifying file. 18# TODO: The usage of paste(1) is a bit of a hack, and for example it does
18# TODO 2: The usage of paste(1) is a bit of a hack, and for example it does
19# not work if filenames contain tab characters. Fix this. 19# not work if filenames contain tab characters. Fix this.
20# Bug (probably not fixing this, use virename): moving moving a file to 20
21# Another TODO: add by filename does not work when globbing filenames with
22# space. E.g. sel add "a file.txt" works, but sel add *.txt does not.
23# Why does this happen?
24
25# Bug (probably not fixing this, use virename): moving a file to
21# itself gives an error and rm is not run. 26# itself gives an error and rm is not run.
22 27
23file="$XDG_DATA_HOME/selectedfiles" 28file="$XDG_DATA_HOME/selectedfiles"
24menu=${MENU:-dmenu} 29menu="" # default uses dmenu-filepicker default
25editor=${EDITOR:-vi} 30editor=${EDITOR:-vi}
26rm=trashrm # replace with rm -r if you don't use trashrm 31rm="trash rm" # replace with rm -r if you don't use trash
27 32
28add() { 33while getopts "m:" opt; do
29 if [ -z "$2" ]; then 34 case "$opt" in
30 dmenu-filepicker >> "$file" 35 m)
31 else 36 menu="$OPTARG"
32 case "$2" in
33 files)
34 ls | while read f; do
35 [ -f "$f" ] && echo "$PWD/$f" >> "$file"
36 done
37 ;;
38 dirs)
39 ls | while read f; do
40 [ -d "$f" ] && echo "$PWD/$f" >> "$file"
41 done
42 ;;
43 all)
44 ls | while read f; do
45 echo "$PWD/$f" >> "$file"
46 done
47 ;;
48 *)
49 echo "$2: not a valid option"
50 ;; 37 ;;
51 esac 38 esac
39done
40shift `expr $OPTIND - 1`
41
42add() {
43 shift 1
44 if [ -z "$1" ]; then
45 if [ -n "$menu" ]; then
46 dmenu-filepicker -m "$menu" >> "$file"
47 else
48 dmenu-filepicker >> "$file"
49 fi
50 else
51 for i in "$@"; do realpath "$i" >> "$file"; done
52 fi 52 fi
53 sort -u -o "$file" "$file"
53} 54}
54 55
55clear() { 56clear() {
@@ -91,7 +92,9 @@ else
91case "$1" in 92case "$1" in
92 add) 93 add)
93 add $@ 94 add $@
94 sort -u -o "$file" "$file" 95 ;;
96 addall)
97 add *
95 ;; 98 ;;
96 clear) 99 clear)
97 clear 100 clear

Generated with cgit - Back to sebastiano.tronto.net