-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrun
executable file
·97 lines (79 loc) · 2.29 KB
/
drun
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
#!/bin/zsh
usage() {
base="$(basename "$0")"
cat >&2 << EOF
Usage:
$ $base -b | bar : Show as a bar on primary screen.
$ $base -c | center : Show as a window centered above focused window.
$ $base -h | help : Show this help.
EOF
[ $# -eq 0 ] || exit "$1"
}
bar() {
L=0
X=$((LGAP))
W=$(($(mattr w "$PFM") - LGAP - RGAP - BW*2))
if [ "$BAR" = "top" ]; then
H=$((TGAP/2 + BW*2))
Y=$((H - TGAP/4))
else
H=$((BGAP/2 + BW*2))
Y=$(($(mattr h "$PRI") - H - BGAP/4))
fi
}
center() {
W="180"
H=$((L * FH))
# finding x y cords for centering
if [ "$PFW" = "$(lsw -r)" ]; then
X=$(($(mattr w "$PFM")/2 - W/2 - 10))
Y=$(($(mattr h "$PFM")/2 - H/2 - 10))
elif [ "$PFW" = "0x00000000" ]; then
X=$(($(mattr w "$PFM")/2 - W/2 - 10))
Y=$(($(mattr h "$PFM")/2 - H/2 - 10))
else
X0="$(mattr x "$PFM")"
Y0="$(mattr y "$PFM")"
X=$(($(wattr x "$PFW") + $(wattr w "$PFW")/2 - W/2 - X0))
Y=$(($(wattr y "$PFW") + $(wattr h "$PFW")/2 - H/2 - Y0))
# move mouse to optimal selection position
wmp -a $(($(wattr x "$PFW") + $(wattr w "$PFW") / 2 - W / 2 + 20)) \
$(($(wattr y "$PFW") + $(wattr h "$PFW") / 2 - H / 2 + 20))
fi
H=$L
}
main() {
. fwmrc
wmenv
wmgaps
dcolours
PFM="$(pfm)"
FONT=$(awk '/font/ {print $3}' < ~/.Xresources | cut -d',' -f 1)
FH=15
L=10
PROMPT=" Run >"
case "$1" in
-b|bar) bar ;;
-c|center) center ;;
-h|help) usage 0 ;;
*) usage 1 ;;
esac
# unfocus from current window to add contrast
focus -u
# grab user program
prg="$(printf '%s\n' "$PATH" | sed 's/:/\n/g' | while read -r dir; do
printf '%s\n' "$(find -L $dir/* -type f -executable)" | \
rev | cut -d/ -f 1 | rev
done | sort -u | \
dmenu -name "drun" -f -i -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 "$H" -bw "$DBW" -l $L)"
# if dmenu returns no output refocus previous window
# else run command
if [ -n "$prg" ]; then
printf '%s\n' "$prg" | ${SHELL:-"/bin/sh"} &
else
focus -w "$PFW"
fi
}
main "$@"