From 3059d88d6ec2c525846a3c9488a4f91036c8068a Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Wed, 30 Nov 2022 12:24:32 +0000 Subject: [PATCH] added ~ replacement in shorten_path to bring it in-line with fish prompt --- functions/shorten_path.fish | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions/shorten_path.fish b/functions/shorten_path.fish index e654b21..3caef7b 100644 --- a/functions/shorten_path.fish +++ b/functions/shorten_path.fish @@ -1,11 +1,13 @@ function shorten_path # shorten_path is a script to compress a path without sacrificing to much readibility # It shortens each segment in a path to one character except the last + # It also replaces /home/user with ~ to save space # e.g.: # /path/to/somewhere → /p/t/somewhere # some/relative/path → s/r/path # singel_segment_path → singel_segment_path # /path/with//empty/space → /p/w//e/space + # /home/user/test/123 → ~/t/123 # handle single segment paths (don't contain a slash) if ! string match -q -- '*/*' $argv[1] @@ -13,8 +15,11 @@ function shorten_path return end + # replace /home/ with ~ + set argv[1] (string replace -r "^$HOME" '~' "$argv[1]") + # split - set -l segments (string split '/' (string trim -r -c '/' $argv[1])) + set -l segments (string split '/' (string trim -r -c '/' "$argv[1]")) # handle relative paths if test -n "$segments[1]"