-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlnks.sh
executable file
·54 lines (45 loc) · 1.24 KB
/
lnks.sh
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
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
if ! type fzf &> /dev/null; then
echo "fzf is not installed" >&2
exit 1
fi
keep_open=false
dir="$(dirname "$0")"
usage () {
echo "Usage: $(basename "$0") [OPTIONS...]"
echo " -k --keep-open Keep lnks open after selecting a bookmark"
echo " -d <dir> --dir <dir> Specify a directory where bookmarks files are stored"
exit 0
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-k|--keep-open) keep_open=true ;;
-d|--dir) dir="$2"; shift ;;
-h|--help) usage ;;
*) echo "Unknown parameter passed: $1" >&2; exit 1 ;;
esac
shift
done
if type explorer.exe &> /dev/null; then
open_command="explorer.exe"
elif type open &> /dev/null; then
open_command="open"
elif type xdg-open &> /dev/null; then
open_command="xdg-open"
fi
enter_command="enter:execute-silent(${open_command} {-1})"
if [ "$keep_open" = true ]; then
enter_command="${enter_command}+clear-query"
else
enter_command="${enter_command}+abort"
fi
cat "$dir"/*.txt | fzf \
--border=rounded \
--prompt="Search Bookmarks > " \
--with-nth='1..-2' \
--bind="${enter_command}" \
--preview='echo {-1}' \
--preview-window='up,1'