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