|
@@ -4,11 +4,7 @@
|
4
|
4
|
### things to do AFTER host/user-specific settings ###
|
5
|
5
|
######################################################
|
6
|
6
|
|
7
|
|
-### .... ###
|
8
|
|
-### BASH ###
|
9
|
|
-### '''' ###
|
10
|
|
-
|
11
|
|
-__make_ps1d() {
|
|
7
|
+__bashum__lastrv() {
|
12
|
8
|
local rvfile="$RV_TMP/$$.lastrv"
|
13
|
9
|
local lastrv="$(cat "$rvfile")"
|
14
|
10
|
local do_rm=false
|
|
@@ -22,69 +18,75 @@ __make_ps1d() {
|
22
|
18
|
$do_rm && rm -f "$rvfile"
|
23
|
19
|
}
|
24
|
20
|
|
25
|
|
-__save_rv() {
|
|
21
|
+__bashum__save_rv() {
|
26
|
22
|
local rvfile="$RV_TMP/$$.lastrv"
|
27
|
23
|
[ -w "${rvfile%/*}" ] && echo "$1" > "$rvfile"
|
28
|
24
|
}
|
29
|
25
|
|
30
|
|
-make_ps1() {
|
|
26
|
+__bashum__mkps1() {
|
31
|
27
|
# these functions must be already defined by ~/.bash/user/*.bashrc
|
32
|
28
|
# and ~/.bash/host/*.bashrc
|
33
|
|
- test -n "$SSH_CONNECTION" && local ps1u=$(make_ps1u)
|
34
|
|
- local ps1h=$(make_ps1h)
|
35
|
|
- local ps1w="$lblue\w$normal";
|
36
|
|
- local ps1G='$(__git_ps1 "(%s)")';
|
37
|
|
- local ps1g="$green$ps1G$normal";
|
38
|
|
- local ps1D='$(__make_ps1d -r)';
|
39
|
|
- local ps1d="$lred$ps1D$normal";
|
40
|
|
- echo "$ps1u$lwhite@$ps1h:$ps1w$ps1g$ps1d\$ ";
|
|
29
|
+ test -n "$SSH_CONNECTION" \
|
|
30
|
+ && echo -n "$(__bashum__mkps1user)" # username only when on ssh
|
|
31
|
+ echo -n "$lwhite@" # nice shiny at sign
|
|
32
|
+ echo -n "$(__bashum__mkps1host):" # hostname colored per host
|
|
33
|
+ echo -n "$lblue\w$normal" # current workdir
|
|
34
|
+ echo -n "$green" #\
|
|
35
|
+ echo -n '$(__git_ps1 "(%s)")' # > git's PS1
|
|
36
|
+ echo -n "$normal" #/
|
|
37
|
+ echo -n "$lred" #\
|
|
38
|
+ echo -n '$(__bashum__lastrv -r)' # > last exit status (nothing if zero)
|
|
39
|
+ echo -n "$normal" #/
|
|
40
|
+ echo '$ ' # obligatory dollar
|
41
|
41
|
}
|
42
|
42
|
|
43
|
|
-make_ps2() {
|
44
|
|
- echo "$white>$yellow>$lyellow>$normal ";
|
|
43
|
+__bashum__mkps2() {
|
|
44
|
+ echo "$white>$yellow>$lyellow>$normal "
|
45
|
45
|
}
|
46
|
46
|
|
47
|
47
|
# and use to assemble own PS1
|
48
|
|
-export PS1=$(make_ps1)
|
49
|
|
-export PS2=$(make_ps2)
|
|
48
|
+export PS1=$(__bashum__mkps1)
|
|
49
|
+export PS2=$(__bashum__mkps2)
|
|
50
|
+
|
50
|
51
|
|
51
|
|
-### ...... ###
|
52
|
|
-### OTHERS ###
|
53
|
|
-### '''''' ###
|
|
52
|
+__bashum__setup_prompt_command() {
|
54
|
53
|
|
55
|
|
-case "$TERM" in
|
|
54
|
+ case "$TERM" in
|
56
|
55
|
|
57
|
|
- xterm*|rxvt*|screen*)
|
58
|
|
- test -n "$SSH_CONNECTION" \
|
59
|
|
- && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
|
60
|
|
- PROMPT_COMMAND='__save_rv $?; echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"'
|
|
56
|
+ xterm*|rxvt*|screen*)
|
|
57
|
+ test -n "$SSH_CONNECTION" \
|
|
58
|
+ && __host_id="${HOSTNAME%%.*}:" # i.e. a remote session
|
|
59
|
+ PROMPT_COMMAND='__bashum__save_rv $?; echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007"'
|
61
|
60
|
|
62
|
|
- # Show the currently running command in the terminal title:
|
63
|
|
- # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
|
64
|
|
- show_command_in_title_bar()
|
65
|
|
- {
|
66
|
|
- case "$BASH_COMMAND" in
|
67
|
|
- *\033]0*)
|
68
|
|
- # The command is trying to set the title bar as well;
|
69
|
|
- # this is most likely the execution of $PROMPT_COMMAND.
|
70
|
|
- # In any case nested escapes confuse the terminal, so don't
|
71
|
|
- # output them.
|
72
|
|
- ;;
|
73
|
|
- "")
|
74
|
|
- echo -ne "\033]0;$(__make_ps1d)$__host_id${PWD/$HOME/\~}\$\007"
|
75
|
|
- ;;
|
76
|
|
- *)
|
77
|
|
- echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007"
|
78
|
|
- ;;
|
79
|
|
- esac
|
80
|
|
- }
|
81
|
|
- trap show_command_in_title_bar DEBUG
|
82
|
|
- ;;
|
|
61
|
+ # Show the currently running command in the terminal title:
|
|
62
|
+ # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
|
|
63
|
+ show_command_in_title_bar()
|
|
64
|
+ {
|
|
65
|
+ case "$BASH_COMMAND" in
|
|
66
|
+ *\033]0*)
|
|
67
|
+ # The command is trying to set the title bar as well;
|
|
68
|
+ # this is most likely the execution of $PROMPT_COMMAND.
|
|
69
|
+ # In any case nested escapes confuse the terminal, so don't
|
|
70
|
+ # output them.
|
|
71
|
+ ;;
|
|
72
|
+ "")
|
|
73
|
+ echo -ne "\033]0;$(__bashum__lastrv)$__host_id${PWD/$HOME/\~}\$\007"
|
|
74
|
+ ;;
|
|
75
|
+ *)
|
|
76
|
+ echo -ne "\033]0;${BASH_COMMAND} ($__host_id${PWD/$HOME/\~})\007"
|
|
77
|
+ ;;
|
|
78
|
+ esac
|
|
79
|
+ }
|
|
80
|
+ trap show_command_in_title_bar DEBUG
|
|
81
|
+ ;;
|
83
|
82
|
|
84
|
|
- *)
|
85
|
|
- PROMPT_COMMAND='__save_rv $?;'
|
86
|
|
- ;;
|
|
83
|
+ *)
|
|
84
|
+ PROMPT_COMMAND='__bashum__save_rv $?;'
|
|
85
|
+ ;;
|
|
86
|
+
|
|
87
|
+ esac
|
|
88
|
+}
|
87
|
89
|
|
88
|
|
-esac
|
|
90
|
+__bashum__setup_prompt_command
|
89
|
91
|
|
90
|
92
|
tasknag
|