-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbashprompt
executable file
·49 lines (44 loc) · 1.3 KB
/
bashprompt
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
#!/bin/bash
#
# bashprompt
#
# if there is an xterm open at a bash prompt, raise/focus that window
# if there isn't start a new xterm
#
# Assumes that your xterm window title includes your short hostname.
# If it doesn't, you should change the prompttitle variable below.
#
# see <http://unix.stackexchange.com/questions/6842> for more details
# and an example .bashrc to set the title (requires bash 3.2 or newer)
#
# Mikel Ward <mikel@mikelward.com>
debug=false
$debug && exec >>$HOME/bashprompt.log 2>&1
# change this to whatever is unique about your window title
# (i.e. a string that appears in the title when the shell is at a prompt
# but does not appear when running a command)
prompttitle="$(hostname -s)"
terminalprog=("gnome-terminal" "--tab" "--maximize")
if ! type wmctrl >/dev/null 2>&1; then
echo "wmctrl can't be found, please install it" 1>&2
exit 1
fi
if ! output="$(wmctrl -l)"; then
echo "Error running wmctrl -l" 1>&2
exit 1
fi
while read -r id desktop host title; do
if [[ $title =~ $prompttitle ]]; then
$debug && echo "$title matches $prompttitle" 1>&2
break
fi
done <<EOF
$output
EOF
if test -n "$id"; then
$debug && echo "Focusing $id" 1>&2
wmctrl -i -a "$id"
else
$debug && echo "Running ${terminalprog[*]}" 1>&2
"${terminalprog[@]}"&
fi