Explorar el Código

~/.bin/ff: Generalize and introduce the "find file" command

Lucas Stadler %!s(int64=8) %!d(string=hace) años
padre
commit
24870f5477
Se han modificado 3 ficheros con 65 adiciones y 20 borrados
  1. 61 0
      .bin/ff
  2. 1 20
      .bin/paper
  3. 3 0
      .bin/video

+ 61 - 0
.bin/ff

@ -0,0 +1,61 @@
1
#!/bin/sh
2
3
# TODO:
4
#
5
# - default to xdg-open
6
# - make program configurable (`-open-with`, implies `-open`?)
7
# - make opening configurable (`-no-open`)
8
#
9
# maybe:
10
#
11
# - use fzf if called from an interactive terminal (?)
12
#   - what about scripts called from the commandline, but that should
13
#     display stuff?  probably they don't exist?
14
# - allow multiple directories to be searched
15
# - make "chooser" configurable (e.g. allow regular dmenu)
16
17
program="xdg-open"
18
base="$PWD"
19
pattern='*.pdf'
20
21
while [ $# -gt 0 ]; do
22
	case "$1" in
23
		-no-open)
24
			program="echo"
25
			shift
26
			;;
27
		-w|-open-with)
28
			shift
29
			program="$1"
30
			shift
31
			;;
32
		-p|-pattern)
33
			shift
34
			pattern="$1"
35
			shift
36
			;;
37
		*)
38
			break
39
			;;
40
	esac
41
done
42
43
case "$1" in
44
	m)
45
		base="$HOME/m/buffer"
46
		pattern='*.mp4'
47
		;;
48
	p)
49
		base="$HOME/d/books/cs"
50
		;;
51
	*)
52
		if [ -n "$1" ]; then
53
			base="$1"
54
		fi
55
		;;
56
esac
57
58
file="$(find "$base" -type f -name "$pattern" -printf '%P\n' | rofi -dmenu -matching normal -sort -i -markup-rows)"
59
if [ "$?" -eq "0" ]; then
60
	$program "$base/$file"
61
fi

+ 1 - 20
.bin/paper

@ -1,22 +1,3 @@
1 1
#!/bin/sh
2 2
3
# TODO:
4
#
5
# - default to xdg-open
6
# - make program configurable (`-open-with`, implies `-open`?)
7
# - make opening configurable (`-no-open`)
8
# - make "chooser" configurable (e.g. allow regular dmenu)
9
#
10
# maybe:
11
#
12
# - use fzf if called from an interactive terminal (?)
13
#   - what about scripts called from the commandline, but that should
14
#     display stuff?  probably they don't exist?
15
# - allow multiple directories to be searched
16
17
base="$HOME/d/books/cs"
18
19
paper="$(find "$base" -type f -name '*.pdf' -printf '%P\n' | rofi -dmenu -matching normal -sort -i -markup-rows)"
20
if [ "$?" -eq "0" ]; then
21
	evince "$base/$paper"
22
fi
3
ff p

+ 3 - 0
.bin/video

@ -0,0 +1,3 @@
1
#!/bin/sh
2
3
ff m