Make column wrap and strip
This commit is contained in:
parent
b2623f0df2
commit
ace88cd18f
2 changed files with 56 additions and 2 deletions
43
.config/fish/functions/construct_column_aware_prompt.fish
Normal file
43
.config/fish/functions/construct_column_aware_prompt.fish
Normal file
|
@ -0,0 +1,43 @@
|
|||
function construct_column_aware_prompt -a prompt_prefix prompt_dir
|
||||
set -l prompt_concat "$prompt_prefix$prompt_dir"
|
||||
|
||||
if test (expr length "$prompt_concat") -le $COLUMNS
|
||||
echo $prompt_prefix$prompt_dir
|
||||
else
|
||||
if test (expr length "$prompt_prefix") -le $COLUMNS
|
||||
set -l split_prompt_concat (string split "/" $prompt_dir)
|
||||
|
||||
if test (count $split_prompt_concat) -lt 2
|
||||
echo (string sub -s 1 -l (math $COLUMNS - (expr length "$prompt_prefix")) $prompt_dir)
|
||||
else
|
||||
for i in (seq (count $split_prompt_concat))
|
||||
if test (expr length "> $split_prompt_concat[$i]/") -gt $COLUMNS
|
||||
set split_prompt_concat[$i] (string sub -s 1 -l (math $COLUMNS - 8) $split_prompt_concat[$i])'[...]'
|
||||
end
|
||||
end
|
||||
|
||||
set -l tmp_lines "$prompt_prefix"
|
||||
|
||||
for item in $split_prompt_concat
|
||||
set -l tmp_line "$tmp_lines$item/"
|
||||
if test (expr length "$tmp_line") -le $COLUMNS
|
||||
set tmp_lines $tmp_line
|
||||
else
|
||||
echo $tmp_lines
|
||||
set tmp_lines "> $item/"
|
||||
end
|
||||
end
|
||||
|
||||
set -l tmp_lines_length (expr length "$tmp_lines")
|
||||
if test $tmp_lines_length -gt 0
|
||||
echo (string sub -s 1 -l (math $tmp_lines_length - 1) $tmp_lines)
|
||||
end
|
||||
end
|
||||
else
|
||||
set -l rec (construct_column_aware_prompt "" $prompt_dir)
|
||||
for item in rec
|
||||
echo $item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,9 +5,20 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set prompt_symbol '$'
|
||||
end
|
||||
|
||||
set -l prompt_prefix (set_color yellow)(whoami)'@'(set_color purple)(prompt_hostname)' '
|
||||
set -l prompt_dir (set_color green)(prompt_pwd)
|
||||
|
||||
set -l column_aware_prompt (construct_column_aware_prompt $prompt_prefix $prompt_dir)
|
||||
|
||||
if test -z $WINDOW
|
||||
printf '%s%s@%s%s %s%s%s %s ' (set_color yellow) (whoami) (set_color purple) (prompt_hostname) (set_color green) (prompt_pwd) (set_color normal) $prompt_symbol
|
||||
for dir in $column_aware_prompt
|
||||
echo $dir
|
||||
end
|
||||
|
||||
set_color normal
|
||||
|
||||
echo $prompt_symbol' '
|
||||
else
|
||||
printf '%s%s@%s%s%s (%s)%s%s%s %s ' (set_color yellow) (whoami) (set_color purple) (prompt_hostname) (set_color white) (echo $WINDOW) (set_color green) (prompt_pwd) (set_color normal) $prompt_symbol
|
||||
printf '%s%s@%s%s%s (%s)%s%s%s\n%s ' (set_color yellow) (whoami) (set_color purple) (prompt_hostname) (set_color white) (echo $WINDOW) (set_color green) (prompt_pwd) (set_color normal) $prompt_symbol
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue