New PS1 with error detection, use vi bindings
David Blume

David Blume commited on 2018-03-30 22:22:41
Showing 4 changed files, with 12 additions and 2 deletions.

... ...
@@ -4,7 +4,13 @@ if [[ $(uname -s) != Darwin* ]] && [ -f /etc/bashrc ]; then
4 4
     . /etc/bashrc
5 5
 fi
6 6
 
7
-export PS1="\h:\W\$ "
7
+if [[ -n $SSH_CLIENT ]]; then
8
+    export PS1='\[\e[48;5;$((!!$?*36+16));38;5;248m\]\h:\W$\[\e[0m\] '
9
+else
10
+    export PS1='\[\e[48;5;$((!!$?*36+16));38;5;248m\]\W$\[\e[0m\] '
11
+fi
12
+
13
+set -o vi
8 14
 
9 15
 add_to_path() {
10 16
     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
... ...
@@ -0,0 +1,3 @@
1
+# OS X: Enable vi mode. Use tab for word completion.
2
+bind -v
3
+bind '\t' rl_complete
... ...
@@ -3,3 +3,4 @@
3 3
 "\e[A":history-search-backward
4 4
 # arrow down
5 5
 "\e[B":history-search-forward
6
+set editing-mode vi
... ...
@@ -3,7 +3,7 @@ set -eu -o pipefail # See: https://sipb.mit.edu/doc/safe-shell/
3 3
 
4 4
 declare -r SCRIPT_NAME=$(basename "$BASH_SOURCE")
5 5
 declare -r backup_dir=$HOME/backup_of_dotfiles_`date "+%Y-%m-%d"`
6
-declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" 
6
+declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" ".editrc"
7 7
                      ".gitconfig" ".gitignore" ".inputrc" ".ssh/config")
8 8
 declare -i DRY_RUN=0
9 9
 
10 10