]> code.delx.au - dotfiles/commitdiff
bash+screen: improvements to xterm titlebar and screen window naming
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 26 Feb 2019 11:32:11 +0000 (22:32 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 26 Feb 2019 11:32:11 +0000 (22:32 +1100)
.bashrc
.screenrc
.ssh/config

diff --git a/.bashrc b/.bashrc
index 8a8408861533eec7bc4aecec7fd241679aa5ca91..36339bc39e2406eef31c3bea537ff6e6555ccde9 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -1,4 +1,5 @@
 # shellcheck disable=SC1090 disable=SC1091 # -- Can't follow non-constant source
+# shellcheck disable=SC1003 # -- Don't complain about '\033\\'
 
 ###########################
 # Settings for all shells #
@@ -63,6 +64,15 @@ export HISTTIMEFORMAT='%F %T '
 
 [ -r /etc/bash_completion ] && source /etc/bash_completion
 
+
+###############
+# Pager setup #
+###############
+
+export PAGER='less'
+export LESS='RS'
+
+
 ##################
 # Terminal setup #
 ##################
@@ -122,13 +132,7 @@ function my_svn_ps1 {
 PS1=''
 PS1="$PS1"'\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
 PS1="$PS1"'\[\033[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
-
-if ! [[ "$TERM" =~ ^screen ]]; then
-    PS1="$PS1"'\n\$ '
-else
-    # matches with shelltitle in .screenrc
-    PS1="$PS1"'\n\[\033k\033\\\]\$> '
-fi
+PS1="$PS1"'\n\$ '
 
 
 #################################
@@ -145,31 +149,15 @@ function print_exit_code {
 trap print_exit_code ERR
 
 
-###############
-# Pager setup #
-###############
-
-export PAGER='less'
-export LESS='RS'
-
-
-################
-# Editor setup #
-################
 
-if emacsclient --version &> /dev/null; then
-    export ALTERNATE_EDITOR='vim'
-    export EDITOR='emacsclient --tty'
+####################
+# Function aliases #
+####################
 
-    if [[ "$TERM" == screen* ]]; then
-        alias edit='emacsclient --tty'
-    else
-        alias edit='emacsclient --create-frame --no-wait'
-    fi
-else
-    export EDITOR='vim'
-    alias edit='vim'
-fi
+# This prevents long/ugly command lines from showing up in xterm titles
+function aliasf {
+    eval "function $1 { $2 \$@; }"
+}
 
 
 ##########################
@@ -202,14 +190,14 @@ alias  l='ls -halF'
 
 alias _psresources='ps -wAo pid,user,%cpu,%mem,stat,start,time,args'
 if [ "$(uname)" = "Linux" ]; then
-    alias pscpu='_psresources --sort -%cpu|less -S'
-    alias psmem='_psresources --sort -%mem|less -S'
-    alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
-    alias pstime='ps -wAo pid,user,lstart,args --sort start_time|less -S'
+    aliasf pscpu '_psresources --sort -%cpu|less -S'
+    aliasf psmem '_psresources --sort -%mem|less -S'
+    aliasf pstree 'ps --forest -weo pid,user:16,args --sort start_time|less -S'
+    aliasf pstime 'ps -wAo pid,user,lstart,args --sort start_time|less -S'
 else
-    alias pscpu='_psresources -r|less -S'
-    alias psmem='_psresources -m|less -S'
-    alias pstime='ps -wAo pid,user,lstart,args|less -S'
+    aliasf pscpu '_psresources -r|less -S'
+    aliasf psmem '_psresources -m|less -S'
+    aliasf pstime 'ps -wAo pid,user,lstart,args|less -S'
 fi
 
 #################
@@ -221,13 +209,12 @@ if echo x | grep -q --color=auto x &> /dev/null; then
     alias grep='grep --color=auto'
 fi
 alias rg='rg -p'
-alias scp='scp -o ControlPath=none'
 alias bc='bc -ql'
 alias watch='watch -n1'
 alias sudo='sudo ' # ability to use aliases with sudo
-alias sudosu='sudo su -l -s /bin/bash'
-alias python='PYTHONSTARTUP=~/.pythonrc.py python3'
-alias webshare='python3 -mhttp.server'
+aliasf sudosu 'sudo su -l -s /bin/bash'
+aliasf python 'PYTHONSTARTUP=~/.pythonrc.py python3'
+aliasf webshare 'python3 -mhttp.server'
 
 if ! command -v pbcopy &> /dev/null; then
     alias pbcopy='xsel --clipboard --input'
@@ -274,6 +261,25 @@ function ssh_unsafe {
 }
 
 
+##################
+# Editor aliases #
+##################
+
+if emacsclient --version &> /dev/null; then
+    export ALTERNATE_EDITOR='vim'
+    export EDITOR='emacsclient --tty'
+
+    if [[ "$TERM" == screen* ]]; then
+        aliasf edit 'emacsclient --tty'
+    else
+        aliasf edit 'emacsclient --create-frame --no-wait'
+    fi
+else
+    export EDITOR='vim'
+    aliasf edit 'vim'
+fi
+
+
 #########################
 # Optional local config #
 #########################
@@ -286,11 +292,34 @@ function ssh_unsafe {
 ##################
 
 # When at a prompt display `hostname:workingdir`
-PROMPT_COMMAND='echo -ne "\\033]0;$(hostname|cut -d. -f1):${PWD/$HOME/\~}\\007"'
+function print_title_prompt {
+    echo -ne "\\033]0;$(hostname|cut -d. -f1):${PWD/$HOME/\~}\\007"
+
+    if [[ "$TERM" == screen* ]]; then
+        echo -ne '\033kbash\033\\'
+    fi
+}
+PROMPT_COMMAND=print_title_prompt
 
 # Display the command about to be executed
 # This must go at the end of bashrc to avoid running the trap on commands in the bashrc
-trap 'echo -ne "\\033]0;$BASH_COMMAND\007"' DEBUG
+function print_title_exec {
+    [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
+
+    echo -ne '\033]0;'
+    echo -n "$BASH_COMMAND" | tr -cd '[:graph:] '
+    echo -ne '\007'
+
+    if [[ "$TERM" == screen* ]]; then
+        echo -ne '\033k'
+        echo -n "$BASH_COMMAND" | \
+            sed 's/^sudo //' | \
+            cut -d' ' -f1 | \
+            tr -cd '[:graph:]'
+        echo -ne '\033\\'
+    fi
+}
+trap print_title_exec DEBUG
 
 
 ###########
index e57db7030e9a35923f31857d106afa80e635831a..319c5ddfdf8230f856489175edb879f66f8a1dea 100644 (file)
--- a/.screenrc
+++ b/.screenrc
@@ -2,7 +2,6 @@ altscreen on
 defbce on
 defscrollback 10000
 escape ^Zz
-shelltitle "> |bash"
 startup_message off
 vbell off
 
index 01ebc172b848960aeede3b0f4cde1e7c3c58bea1..3b471e9e02689a97f393b4c3ba1bcbfbf9ee841c 100644 (file)
@@ -1,6 +1,4 @@
 Host *
     HashKnownHosts no
     SendEnv COLORFGBG
-###    ControlMaster auto
-###    ControlPath ~/.ssh/master-%r@%h:%p