From cbd8cdbe550982b2bd5a315c0dd39057521b50c8 Mon Sep 17 00:00:00 2001 From: Bartek Stalewski Date: Thu, 2 Jan 2020 13:55:02 +0100 Subject: [PATCH] abbreviated prompt --- zsh/abbr_pwd | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 zsh/abbr_pwd diff --git a/zsh/abbr_pwd b/zsh/abbr_pwd new file mode 100644 index 0000000..c5e3893 --- /dev/null +++ b/zsh/abbr_pwd @@ -0,0 +1,41 @@ +#!/bin/zsh + +function felix_pwd_abbr { + base_pwd=$PWD + tilda_notation=${base_pwd//$HOME/\~} + pwd_list=(${(s:/:)tilda_notation}) + list_len=${#pwd_list} + + if [[ $list_len -le 1 ]]; then + echo $tilda_notation + return + fi + + if [[ ${pwd_list[1]} != '~' ]]; then + formed_pwd='/' + fi + + firstchar=$(echo ${pwd_list[1]} | cut -c1) + if [[ $firstchar == '.' ]] ; then + firstchar=$(echo ${pwd_list[1]} | cut -c1,2) + fi + + formed_pwd=${formed_pwd}$firstchar + + for ((i=2; i <= $list_len; i++)) do + if [[ $i != ${list_len} ]]; then + + firstchar=$(echo ${pwd_list[$i]} | cut -c1) + if [[ $firstchar == '.' ]] ; then + firstchar=$(echo ${pwd_list[$i]} | cut -c1,2) + fi + + formed_pwd=${formed_pwd}/$firstchar + else + formed_pwd=${formed_pwd}/${pwd_list[$i]} + fi + done + + echo $formed_pwd + return +}