fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a53db7256
master
1# localization: skip(private) 2function __fish_paste 3# Also split on \r, otherwise it looks confusing 4set -l data( string split\r --$argv [ 1 ] | string split\n ) 5set data( string replace -ra[[ :cntrl:]] '' --$data ) 6 7if commandline --search-field> /dev/null 8commandline --search-field -i --$data 9return 10end 11 12# If the current token has an unmatched single-quote, 13# escape all single-quotes (and backslashes) in the paste, 14# in order to turn it into a single literal token. 15# 16# This eases pasting non-code (e.g. markdown or git commitishes). 17set -l quote_state( __fish_tokenizer_state --( commandline -ct| string collect)) 18if contains --$quote_state single single-escaped 19if status test-feature regex-easyesc 20set data( string replace -ra"(['\\\])" '\\\\$1' --$data ) 21else 22set data( string replace -ra"(['\\\])" '\\\\\\\$1' --$data ) 23end 24else if not contains --$quote_state double double-escaped 25and set -q data[ 2 ] 26# Leading whitespace in subsequent lines is unneded, since fish 27# already indents. Also gets rid of tabs (issue #5274). 28set -l tmp 29for linein $data 30switch $quote_state 31case normal 32set -a tmp( string trim -l --$line ) 33case single single-escaped double double-escaped escaped 34set -a tmp$line 35end 36set quote_state( __fish_tokenizer_state -i$quote_state --$line ) 37end 38set data$data [ 1 ] $tmp [ 2 .. ] 39end 40if not string length -q --( commandline -c) 41# If we're at the beginning of the first line, trim whitespace from the start, 42# so we don't trigger ignoring history. 43set data[ 1 ] ( string trim -l --$data [ 1 ]) 44end 45 46if test -n " $data " 47commandline --insert-smart --$data 48end 49end