-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·143 lines (124 loc) · 4.24 KB
/
Copy pathinstall
File metadata and controls
executable file
·143 lines (124 loc) · 4.24 KB
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
#!/bin/sh
# Install xfce-tiler for the current user.
#
# ./install into ~/.local/bin
# ./install --shortcuts bind Super+1..4, Super+arrows and Super+Tab
# ./install --all all of the above
# ./install --dry-run print what would happen
set -eu
SRC="$(cd "$(dirname "$0")" && pwd)"
BIN="$HOME/.local/bin"
STAMP="$(date +%Y%m%d%H%M%S)"
SCRIPTS="tile"
# key:arguments bound as "$BIN/tile <arguments>"
BINDINGS="<Super>1:slot 1
<Super>2:slot 2
<Super>3:slot 3
<Super>4:slot 4
<Super>Left:dir left
<Super>Right:dir right
<Super>Up:dir up
<Super>Down:dir down"
DO_SHORTCUTS=0
DRY=0
for arg in "$@"; do
case "$arg" in
--shortcuts) DO_SHORTCUTS=1 ;;
--all) DO_SHORTCUTS=1 ;;
--dry-run|-n) DRY=1 ;;
--help|-h)
sed -n '2,/^$/p' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*)
echo "install: unknown option $arg (try --help)" >&2
exit 2
;;
esac
done
say() { printf '%s\n' "$*"; }
run() {
if [ "$DRY" = 1 ]; then
printf ' would run: %s\n' "$*"
else
"$@"
fi
}
backup() {
[ -e "$1" ] || return 0
cmp -s "$1" "$2" 2>/dev/null && return 0 # Identical
say " backing up $1 -> $1.bak-$STAMP"
run cp -p "$1" "$1.bak-$STAMP"
}
missing=""
for tool in python3 xfconf-query; do
command -v "$tool" >/dev/null 2>&1 || missing="$missing $tool"
done
[ -n "$missing" ] && say "WARNING: not found on PATH:$missing"
python3 - <<'PY' 2>/dev/null || say "WARNING: libX11 not found!"
import ctypes, ctypes.util, sys
sys.exit(0 if ctypes.util.find_library("X11") else 1)
PY
say "Installing scripts into $BIN"
run mkdir -p "$BIN"
for s in $SCRIPTS; do
[ -f "$SRC/$s" ] || { say " MISSING in repo: $s"; continue; }
backup "$BIN/$s" "$SRC/$s"
run cp "$SRC/$s" "$BIN/$s"
run chmod +x "$BIN/$s"
say " $s"
done
case ":$PATH:" in
*":$BIN:"*) ;;
*) say "NOTE: $BIN is not on PATH. Shortcuts use full path, so they"
say " still work, but 'tile' will not run from shell." ;;
esac
if [ "$DO_SHORTCUTS" = 1 ]; then
say "Creating XFCE keyboard shortcuts"
if ! command -v xfconf-query >/dev/null 2>&1; then
say " xfconf-query not found; add the shortcuts by hand (look at README)"
else
echo "$BINDINGS" | while IFS= read -r pair; do
key="${pair%%:*}"
args="${pair#*:}"
prop="/commands/custom/$key"
if [ "$DRY" = 1 ]; then
say " would bind $key -> $BIN/tile $args"
continue
fi
old="$(xfconf-query -c xfce4-keyboard-shortcuts -p "$prop" 2>/dev/null || true)"
case "$old" in
""|*"/tile "*) ;;
*) say " NOTE: $key was bound to '$old', replacing it" ;;
esac
xfconf-query -c xfce4-keyboard-shortcuts -p "$prop" -r >/dev/null 2>&1 || true
if xfconf-query -c xfce4-keyboard-shortcuts -p "$prop" \
-n -t string -s "$BIN/tile $args" >/dev/null 2>&1; then
say " $key -> tile $args"
else
say " FAILED to bind $key; add it by hand: $BIN/tile $args"
fi
done
if [ "$DRY" = 1 ]; then
say " would free <Super>Tab from xfwm4 so tile can read it as a chord"
else
xfconf-query -c xfce4-keyboard-shortcuts \
-p "/xfwm4/custom/<Super>Tab" -n -t string -s "empty" \
>/dev/null 2>&1 || true
xfconf-query -c xfce4-keyboard-shortcuts \
-p "/commands/custom/<Super>Tab" -r >/dev/null 2>&1 || true
if xfconf-query -c xfce4-keyboard-shortcuts \
-p "/commands/custom/<Super>Tab" -n -t string -s "/bin/true" \
>/dev/null 2>&1; then
say " <Super>Tab -> swallowed (chord modifier for Super+Tab+1..4)"
else
say " FAILED to swallow <Super>Tab; Tab may reach the focused app :("
fi
fi
fi
else
say "XFCE shortcuts NOT created. ./install --shortcuts, or bind them by hand in"
say " Settings -> Keyboard -> Application Shortcuts (see README)."
fi
say ""
say "All done!"