added ~ replacement in shorten_path to bring it in-line with fish prompt

master
Anton Lydike 2 years ago
parent a2241ffb65
commit 3059d88d6e

@ -1,11 +1,13 @@
function shorten_path function shorten_path
# shorten_path is a script to compress a path without sacrificing to much readibility # 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 shortens each segment in a path to one character except the last
# It also replaces /home/user with ~ to save space
# e.g.: # e.g.:
# /path/to/somewhere → /p/t/somewhere # /path/to/somewhere → /p/t/somewhere
# some/relative/path → s/r/path # some/relative/path → s/r/path
# singel_segment_path → singel_segment_path # singel_segment_path → singel_segment_path
# /path/with//empty/space → /p/w//e/space # /path/with//empty/space → /p/w//e/space
# /home/user/test/123 → ~/t/123
# handle single segment paths (don't contain a slash) # handle single segment paths (don't contain a slash)
if ! string match -q -- '*/*' $argv[1] if ! string match -q -- '*/*' $argv[1]
@ -13,8 +15,11 @@ function shorten_path
return return
end end
# replace /home/<username> with ~
set argv[1] (string replace -r "^$HOME" '~' "$argv[1]")
# split # 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 # handle relative paths
if test -n "$segments[1]" if test -n "$segments[1]"

Loading…
Cancel
Save