aboutsummaryrefslogtreecommitdiffstats
path: root/zsh/.zsh/functions/spwd
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-06-14 22:15:26 -0700
committerGravatar Tom Willemse2022-06-14 22:16:49 -0700
commit46259edd2d39e2513b77eea1b9ce83a2c5b826c7 (patch)
tree0d8366e7d3850af07edd9ea9e7daf554be62860f /zsh/.zsh/functions/spwd
parent7c507732f7c3b5f3fe0caea53e28cf4ad5d3d93a (diff)
downloadnew-dotfiles-46259edd2d39e2513b77eea1b9ce83a2c5b826c7.tar.gz
new-dotfiles-46259edd2d39e2513b77eea1b9ce83a2c5b826c7.zip
Update ZSH prompt
Include a shortened version of the current directory.
Diffstat (limited to 'zsh/.zsh/functions/spwd')
-rw-r--r--zsh/.zsh/functions/spwd25
1 files changed, 25 insertions, 0 deletions
diff --git a/zsh/.zsh/functions/spwd b/zsh/.zsh/functions/spwd
new file mode 100644
index 0000000..15aef1b
--- /dev/null
+++ b/zsh/.zsh/functions/spwd
@@ -0,0 +1,25 @@
+# From https://stackoverflow.com/a/45336078
+paths=(${(s:/:)PWD})
+
+cur_path='/'
+cur_short_path='/'
+for directory in ${paths[@]}
+do
+ cur_dir=''
+ for (( i=0; i<${#directory}; i++ )); do
+ cur_dir+="${directory:$i:1}"
+ matching=("$cur_path"/"$cur_dir"*/)
+ if [[ ${#matching[@]} -eq 1 ]]; then
+ break
+ fi
+ done
+ cur_short_path+="$cur_dir/"
+ cur_path+="$directory/"
+
+ if [[ $cur_path == $HOME/ ]];
+ then cur_short_path='~/'
+ fi
+done
+
+printf %b "${cur_short_path: : -1}"
+echo