forked from huijunchen9260/dmenufm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmenufm
executable file
·219 lines (193 loc) · 7.26 KB
/
dmenufm
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/sh
# source configuration file
FM_PATH="$HOME/.config/dmenufm"
FM_CACHE_PATH="$HOME/.cache/dmenufm"
configuration () {
if [ -r "$FM_PATH/dmenufm.conf" ]; then
. "$FM_PATH/dmenufm.conf"
elif [ -r "/etc/dmenufm.conf" ]; then
. "/etc/dmenufm.conf"
else
echo 'Run `sudo make install` first to install all dmenufm files.'
fi
}
Program () {
case $FM_PROG in
"fzf")
[ -z "$FM_OPTS" ] && FM_OPTS="--reverse"
[ -z "$FM_OPTS_GENERIC" ] && FM_OPTS_GENERIC=""
[ -z "$FM_OPTS_ACTION_LV1" ] && FM_OPTS_ACTION_LV1=""
[ -z "$FM_OPTS_ACTION_LV2" ] && FM_OPTS_ACTION_LV2=""
[ -z "$FM_OPTS_ACTION_BULK" ] && FM_OPTS_ACTION_BULK=""
FM_OPT_PROMPT="--prompt"
;;
"bemenu")
[ -z "$FM_OPTS" ] && FM_OPTS="-l 10"
[ -z "$FM_OPTS_GENERIC" ] && FM_OPTS_GENERIC="--sb='#005577'"
[ -z "$FM_OPTS_ACTION_LV1" ] && FM_OPTS_ACTION_LV1="--sb='#33691e'"
[ -z "$FM_OPTS_ACTION_LV2" ] && FM_OPTS_ACTION_LV2="--sb='#FF8C00'"
[ -z "$FM_OPTS_ACTION_BULK" ] && FM_OPTS_ACTION_BULK="--sb='#CB06CB'"
FM_OPT_PROMPT="-p"
;;
"rofi")
[ -z "$FM_OPTS" ] && FM_OPTS="-dmenu -l 10"
[ -z "$FM_OPTS_GENERIC" ] && FM_OPTS_GENERIC="-sb '#005577'"
[ -z "$FM_OPTS_ACTION_LV1" ] && FM_OPTS_ACTION_LV1="-sb '#33691e'"
[ -z "$FM_OPTS_ACTION_LV2" ] && FM_OPTS_ACTION_LV2="-sb '#FF8C00'"
[ -z "$FM_OPTS_ACTION_BULK" ] && FM_OPTS_ACTION_BULK="-sb '#CB06CB'"
FM_OPT_PROMPT="-p"
;;
"shellect")
[ -z "$FM_OPTS" ] && FM_OPTS='-i -l'
[ -z "$FM_OPTS_GENERIC" ] && FM_OPTS_GENERIC=""
[ -z "$FM_OPTS_ACTION_LV1" ] && FM_OPTS_ACTION_LV1=""
[ -z "$FM_OPTS_ACTION_LV2" ] && FM_OPTS_ACTION_LV2=""
[ -z "$FM_OPTS_ACTION_BULK" ] && FM_OPTS_ACTION_BULK=""
FM_OPT_PROMPT='-t'
;;
"") [ "$termpath" = "true" ] || echo "No program selected, falling back to dmenu." ;;
*)
[ -z "$FM_OPTS" ] && FM_OPTS=""
[ -z "$FM_OPT_PROMPT" ] && FM_OPT_PROMPT="" && echo "Program \`$FM_PROG\` not recognized, trying to run without any option. If this does not work, please set both \'$FM_OPTS\' and \'$FM_OPT_PROMPT\' variable!"
;;
esac
}
# SUDO setting
export SUDO_ASKPASS="$FM_SDOPROP"
## GLOBAL VARIABLES
CHOICE="placeholder"
actCHOICE="placeholder"
allselection="placeholder"
masselection="placeholder"
TARGET="./"
BACKWARD="../"
ENDSELECTION="End Selection"
allowbulk="NotAllowed"
ACTION="Actions"
TERM="Terminal"
OPENIN='Open in...'
FM_PCP="PCP - Copy path"
FM_NEW="NEW - Create new file / directory"
FM_DEL="DEL - Delete files / directories"
FM_MVV="MVV - Move files / directories"
FM_YAK="YAK - Copy files / directories"
FM_LNK="LNK - Symbolically link files / directories"
FM_REM="REM - Rename files / directories"
FM_TRH="TRH - Trash of dmenufm"
FM_HIS="HIS - History of dmenufm"
FM_BMK="BMK - Bookmark for dmenufm"
FM_CMD="CMD - Frequently used command"
FM_ZIP="ZIP - Compress files / directories"
FM_SDO="SDO - Enable Super user privilege"
FM_EYE="EYE - Preview files"
ACTLIST=$(printf '%s\n' "$FM_PCP" "$FM_NEW" "$FM_MVV" "$FM_YAK" "$FM_LNK" "$FM_DEL" "$FM_TRH" "$FM_REM" "$FM_HIS" "$FM_BMK" "$FM_CMD" "$FM_ZIP" "$FM_SDO" "$FM_EYE")
COMPRESSIONLIST=$(printf '%s\n' "tar.gz" "tar.bz2" "tar.xz" "xz" "lzma" "gz" "bz2" "7z" "zip")
nl='
'
configuration
# Create files / directories
[ ! -d "$FM_PATH" ] && mkdir -p "$FM_PATH"
[ ! -f "$FM_PATH/dmenufm.conf" ] && cp "/etc/dmenufm.conf" "$FM_PATH/dmenufm.conf"
[ ! -d "$FM_CACHE_PATH" ] && mkdir -p "$FM_CACHE_PATH"
[ ! -d "$FM_TRASH" ] && mkdir -p "$FM_TRASH"
printf '%s\n' '#!/bin/sh' > "$FM_SDOPROP"
printf '%s ' "printf '%s' \"\" | ${FM_PROG-dmenu} ${FM_OPTS--fn Monospace-18 -sb \"#FEE12B\" -sf \"#1d2021\" -nf \"#000000\" -nb \"#000000\"} ${FM_OPT_PROMPT--p}" '"$1 " && echo' >> "$FM_SDOPROP"
chmod +x "$FM_SDOPROP"
. dmenufm-open
. dmenufm-action
. dmenufm-menu
CheckDeps () {
for CurDep in "$@"; do
command -v "$CurDep" 1> /dev/null 2>&1 || printf '%s\n' "ERROR: Dependency $CurDep not met." 1>&2
done
unset CurDep
}
CheckDeps find tail sed grep cp mv rm paste cut id wmctrl touch
GetOS () {
# Stolen from fff
case $OSTYPE in
darwin*) opener=open; clipcopy=pbcopy ;;
*) { command -v xclip 1> /dev/null 2>&1 && clipcopy=xclip; } || { command -v xsel 1> /dev/null 2>&1 && clipcopy=xsel; } ;;
esac
}
UsageInfo () {
while read -r CurLine; do
printf "%b\n" "$CurLine"
done <<-EOF
\r DMENUFM
\r Written by huijunchen9260 ([email protected])
\r
\r Simple file manager using dmenu
\r
\rSYNTAX: dmenufm [OPTS]
\r
\rOPTS: -h | --help - Show this usage information.
\r -d | --directory - Only directories.
\r -f | --file - Only show files.
\r -D | --dotdirectory - Only show hidden directories.
\r -F | --dotfile - Only show hidden files.
\r -p | --lastpath - Opens in last working directory. (cd on exit)
\r -r | --rollingmenu - Rolling menu based on selected files.
\r -t | --termpath - Print out the path of file / directory.
\r -m | --menu - Choose other menu system
\r -o | --option - Choose options for other menu system
\r -no | --notif-option - Choose NotiPrompt options for other menu system
\r -do | --danger-option - Choose DangerPrompt options for other menu system
EOF
unset CurLine
}
### ARGUMENTS
while [ -n "$1" ]; do
case $1 in
"-d"|"--directory" ) keeplist="${keeplist} DIRs" ;;
"-f"|"--file" ) keeplist="${keeplist} FILEs" ;;
"-D"|"--dotdirectory" ) keeplist="${keeplist} DOTDIRs" ;;
"-F"|"--dotfile" ) keeplist="${keeplist} DOTFILEs" ;;
"-p"|"--lastpath" ) outputpath="placeholder" ;;
"-r"|"--rollingmenu") rollingmenu="true" ;;
"-t"|"--termpath") termpath="true" ;;
"-m"|"--menu") shift; FM_PROG="$1" ;;
"-o"|"--option") shift; FM_OPTS="$1" ;;
"-no"|"--notif-option") shift; FM_NOTIF_OPTS="$1" ;;
"-do"|"--danger-option") shift; FM_DANGER_OPTS="$1" ;;
"-h"|"--help" ) UsageInfo; exit 0; ;;
*)
if [ -d "$1" ]; then
cd "$1" || exit 1
elif [ -f "$1" ]; then
FileOpen "$1"
else
printf '%s\n' "Invalid option. Use -h to read help"
exit 1
fi
;;
esac
shift
done
### RUN THE MAIN FUNCTION
# --lastpath option:
[ -n "$outputpath" ] && cd "$(cat -u "$FM_LASTPATH")"
if [ "$(id -u)" -eq 0 ]; then
# super user privilege
yprompt () { # Usage yprompt [MSG] [BG_COLOR]
${FM_PROG:-dmenu} ${FM_OPTS--f -i -l 10} $2 ${FM_OPT_PROMPT--p} "SUDO: $1 "
}
xprompt () { # Usage xprompt [MSG] [BG_COLOR]
printf '%s' "" | ${FM_PROG-dmenu} ${FM_OPTS--f -i -l 10} $2 ${FM_OPT_PROMPT--p} "SUDO: $1 "
}
NotiPrompt () { # Usage NotiPrompt [MSG]
printf '%s' "" | ${FM_PROG-dmenu} ${FM_OPTS--f -i -l 10} ${FM_NOTIF_OPTS--fn "$FM_NOTIF_FONT" -sb "#d79921" -sf "#1d2021" -nf "#000000" -nb "#000000"} ${FM_OPT_PROMPT--p} "SUDO: $1 "
}
DangerPrompt () { # Usage: DangerPrompt [MSG] && ...
[ "$(printf "No\\nYes" | ${FM_PROG-dmenu} ${FM_OPTS--f -i -l 10} ${FM_DANGER_OPTS--fn $FM_DANGER_FONT -nb darkred -sb red -sf white -nf gray} ${FM_OPT_PROMPT--p} "$1")" = "Yes" ]
}
FM_GENERIC_COLOR="$FM_SUDO_COLOR"
GetOS
Program
MainMenu
else
GetOS
Program
MainMenu
fi
printf '%s' "$PWD" > "$FM_LASTPATH"