fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Charles MaherAdd feature to fish_commandline_prepend and fix minor issue (#9261)1dd8a113f

master
867 B26 linesraw
1function fish_commandline_prepend --description "Prepend the given string to the command-line, or remove the prefix if already there"
2    if not commandline | string length -q
3        commandline -r $history[1]
4    end
5
6    set -l process (commandline -p | string collect)
7
8    set -l to_prepend "$argv[1] "
9    if string match -qr '^ ' "$process"
10        set to_prepend " $argv[1]"
11    end
12
13    set -l length_diff (string length -- "$to_prepend")
14    set -l cursor_location (commandline -pC)
15
16    set -l escaped (string escape --style=regex -- $to_prepend)
17    if set process (string replace -r -- "^$escaped" "" $process)
18        commandline --replace -p -- $process
19        set length_diff "-$length_diff"
20    else
21        commandline -pC 0
22        commandline -pi -- "$to_prepend"
23    end
24
25    commandline -pC (math "max 0,($cursor_location + $length_diff)")
26end