-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdmenu
executable file
·128 lines (105 loc) · 2.55 KB
/
cmdmenu
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
#!/bin/sh
#
# cmdmenu
usage() {
base=$(basename "$0")
cat >&2 << EOF
Usage:
$ $base
EOF
[ $# -eq 0 ] || exit "$1"
}
wmenus() {
processes="open
move
resize
ssh
shot
pfw
delete
off"
export processes
}
sel() {
sleep 0.2
wid="$(slw)"
[ "$wid" = "$(lsw -r)" ] && exit 0
case "$1" in
shot) shot "$wid" ;;
delete) killw "$wid" ;;
resize) chwso -r "$wid"; xmrs "$wid" ;;
move) chwso -r "$wid"; xmmv "$wid" ;;
place) chwso -r "$wid"; sh -c "wtp $(xrectsel '%x %y %w %h') $wid" ;;
esac
}
new() {
sleep 0.2
fw=5
fh=10
ib=10
ob=2
xrectsel '%w %h %x %y' | {
read -r w h x y
if [ "$w" -lt 100 ]; then
exec urxvtc -g 85x22
elif [ "$h" -lt 100 ]; then
exec urxvtc -g 85x22
else
w=$(( ( w - (ib + ob)*2 ) / fw ))
h=$(( ( h - (ib + ob)*2 ) / fh ))
exec urxvtc -g "${w}x${h}"
fi
}
}
open() {
# use link handling program of your choosing
load "$(xsel -o)"
}
menu() {
# menu geometry
X0="$(mattr x "$PFM")"
Y0="$(mattr y "$PFM")"
mouse="$(wmp)"
X=$((${mouse% *} - X0 - 20))
Y=$((${mouse#* } - Y0 - 20))
}
main() {
. fwmrc
wmenv
wmgaps
wmenus
dcolours
PFM="$(pfm)"
FONT=$(awk '/font/ {print $3}' < ~/.Xresources | cut -d',' -f 1)
FH="15"
W="100"
PROMPT=" Do >"
case "$1" in
-h|--help|help) usage 0 ;;
*) menu ;;
esac
L="$(printf '%s\n' "$processes" | wc -l)"
# unfocus from current window to add contrast
focus -u
# grab command to run
process=$(printf '%s\n' "$processes" | \
dmenu -name "$(basename "$0")" -f -l "$L" -fn "$FONT" -p "$PROMPT" \
-nf "#$NF" -sf "#$SF" -nb "#$NB" -sb "#$SB" -bc "#$BC" \
-s "$(mattr d "$PFM")" -x $X -y $Y -w "$W" -h "$FH" -bw "$DBW")
# if dmenu returns no output refocus previous window
# else run command
case "$process" in
new) new ;;
ssh) sshmenu -m ;;
move) sel move ;;
select) wmenu -m ;;
resize) sel resize ;;
delete) sel delete ;;
open) openmenu -m ;;
shot) shot pri ;;
pfw) sel shot ;;
off) poweroff ;;
*) focus -w "$PFW" nojump ;;
esac
}
main "$@"