]> git.phdru.name Git - dotfiles.git/commitdiff
bash: Use custom `short_curdir` instead of `\W` in `PS1`
authorOleg Broytman <phd@phdru.name>
Sun, 7 Jun 2020 21:38:39 +0000 (00:38 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 7 Jun 2020 22:33:47 +0000 (01:33 +0300)
.profile
.shellrc
admin/prog/short_curdir [new file with mode: 0644]

index c287c85ea75a3bc65e2285e35393ed6b5915daaa..2cfb9431d9ad69cb6251fd751ebad263467f4035 100644 (file)
--- a/.profile
+++ b/.profile
@@ -192,7 +192,12 @@ if [ -t 0 ] ; then
          ;;
       esac
 
          ;;
       esac
 
-      OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \W \\$"
+      if [ -r "$HOME"/admin/prog/short_curdir ]; then
+         . "$HOME"/admin/prog/short_curdir
+         OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \`short_curdir\` \\$"
+      else
+         OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \W \\$"
+      fi
       . "$ENV"
 
    else
       . "$ENV"
 
    else
index a68887656de63857c2555f706cf45bd7462ce040..541417a422ae2ff1c5040e1e58c70f74b8867034 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -152,6 +152,11 @@ if test -n "$BASH_VERSION"; then
    fi
    complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
 
    fi
    complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser
 
+   if [ "`type -t short_curdir`" != function -a \
+         -r "$HOME"/admin/prog/short_curdir ]; then
+      . "$HOME"/admin/prog/short_curdir
+   fi
+
    #if type -p pip >/dev/null 2>&1; then
    #   eval "`pip completion --bash`"
    #   rm -rf /tmp/pip_build_"$USER"
    #if type -p pip >/dev/null 2>&1; then
    #   eval "`pip completion --bash`"
    #   rm -rf /tmp/pip_build_"$USER"
@@ -336,7 +341,11 @@ include() {
 mc() {
    if test -n "$BASH_VERSION"; then
       MC_SAVE_OPS1="$OPS1"
 mc() {
    if test -n "$BASH_VERSION"; then
       MC_SAVE_OPS1="$OPS1"
-      OPS1="\u@\h \W \\$"
+      if [ "`type -t short_curdir`" = function ]; then
+         OPS1="\u@\h \`short_curdir\` \\$"
+      else
+         OPS1="\u@\h \W \\$"
+      fi
    fi
 
    if [ -n "$SLOWTERM" ]; then
    fi
 
    if [ -n "$SLOWTERM" ]; then
diff --git a/admin/prog/short_curdir b/admin/prog/short_curdir
new file mode 100644 (file)
index 0000000..62ede06
--- /dev/null
@@ -0,0 +1,16 @@
+short_curdir() {
+   if [ "$PWD" = / ]; then
+      echo /
+      return
+   fi
+   if [ "$PWD" = "$HOME" ]; then
+      echo "~"
+      return
+   fi
+   local _short_curdir
+   _short_curdir="${PWD##*/}" # cut all directories, get base name
+   if [ "${#_short_curdir}" -gt 15 ]; then
+      _short_curdir="${_short_curdir::15}..." # cut long string
+   fi
+   echo "${_short_curdir}"
+}