-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvxfce.sh
110 lines (92 loc) · 2.09 KB
/
nvxfce.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
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
#!/bin/sh
# First argument is the search string or cmd option
# Folder containing notes
zimConfig="${HOME}/.config/zim/notebooks.list"
# Save selected notbook and rearrange args.
if test $(expr $1 : '[-].*') = 0
then
let notebook="$1"
set -- "${@:2:${#@}}"
else
notebook="D"
fi
while read -r line
do
if test "${line::1}" = "$notebook"
then
# echo "$line ${line::1}"
index=$(expr "$line" : '.*.=.')
noteDir=${HOME}${line:$index}
# ger last string after '/'
noteName=${line##*/}
fi
# echo $line
done < $zimConfig
cd $noteDir
# ========================
_run_noteApp()
{
# nohup = ignore hangup signals
nohup zim --standalone $noteName "$1" & disown
exit
}
# USAGE: nvxfce.sh [Notebook number] [option] String to search
# -s search
# -c search content
# no argument, creates new list with argument name given ""
let i=1
# if first argument "-c" searches content and not title
if test $1 = "-c"
then
search_str="${@:2:${#@}}"
for filename in $(grep -Hrli "$search_str" *)
do
list[$i]="${filename}"
let i++
done
elif test $1 = "-s"
then
# search and replace spaces for '_'
printf -v nospace "_%s" "${@:2:${#@}}"
nospace=${nospace:1}
for filename in *
do
if test $(expr match "$filename" "$nospace") -gt 0
then
list[$i]="${filename}"
let i++
fi
done
# printf "%s\n" ${list[@]}
else
_run_noteApp "$1"
fi
# reset counter
let i=0
# List all containing search string
for f in ${list[@]};
do
let i++
printf "%3d %s\n" $i $f
done
# exits program if no results
if test $i = "0"
then
echo "No results found!"
exit
# if only one item in list, select it
elif test $i = "1"
then
_run_noteApp ${list[1]%.txt}
exit
fi
# promt user for selection
printf "\n%s" "Enter your choice (1-${i}) then press [enter] :"
read selection
# If user press empty enter or emulator skips selection,
# this ensures at least one valid selection.
if test -z "$selection"
then
selection=1
fi
_run_noteApp ${list[$selection]%.txt}