Add fish autopair plugin
This commit is contained in:
parent
f383bf3240
commit
669c75da97
39
fish/.config/fish/conf.d/autopair.fish
Normal file
39
fish/.config/fish/conf.d/autopair.fish
Normal file
@ -0,0 +1,39 @@
|
||||
status is-interactive || exit
|
||||
|
||||
set --global autopair_left "(" "[" "{" '"' "'"
|
||||
set --global autopair_right ")" "]" "}" '"' "'"
|
||||
set --global autopair_pairs "()" "[]" "{}" '""' "''"
|
||||
|
||||
function _autopair_fish_key_bindings --on-variable fish_key_bindings
|
||||
set --query fish_key_bindings[1] || return
|
||||
|
||||
test $fish_key_bindings = fish_default_key_bindings &&
|
||||
set --local mode default insert ||
|
||||
set --local mode insert default
|
||||
|
||||
bind --mode $mode[-1] --erase \177 \b \t
|
||||
|
||||
bind --mode $mode[1] \177 _autopair_backspace # macOS ⌫
|
||||
bind --mode $mode[1] \b _autopair_backspace
|
||||
bind --mode $mode[1] \t _autopair_tab
|
||||
|
||||
printf "%s\n" $autopair_pairs | while read --local left right --delimiter ""
|
||||
bind --mode $mode[-1] --erase $left $right
|
||||
if test $left = $right
|
||||
bind --mode $mode[1] $left "_autopair_insert_same \\$left"
|
||||
else
|
||||
bind --mode $mode[1] $left "_autopair_insert_left \\$left \\$right"
|
||||
bind --mode $mode[1] $right "_autopair_insert_right \\$right"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
_autopair_fish_key_bindings
|
||||
|
||||
function _autopair_uninstall --on-event autopair_uninstall
|
||||
string collect (
|
||||
bind --all | string replace --filter --regex -- "_autopair.*" --erase
|
||||
set --names | string replace --filter --regex -- "^autopair" "set --erase autopair"
|
||||
) | source
|
||||
functions --erase (functions --all | string match "_autopair_*")
|
||||
end
|
@ -1,3 +1,4 @@
|
||||
jorgebucaran/fisher
|
||||
ilancosman/tide@v6
|
||||
jethrokuan/z
|
||||
jorgebucaran/autopair.fish
|
||||
|
@ -9,8 +9,9 @@ SETUVAR Z_EXCLUDE:\x5e/home/tim\x24
|
||||
SETUVAR __fish_initialized:3400
|
||||
SETUVAR _fisher_ilancosman_2F_tide_40_v6_files:\x7e/\x2econfig/fish/functions/_tide_1_line_prompt\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_2_line_prompt\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_cache_variables\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_detect_os\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_find_and_remove\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_fish_colorize\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_aws\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_character\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_cmd_duration\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_context\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_crystal\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_direnv\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_distrobox\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_docker\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_elixir\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_gcloud\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_git\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_go\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_java\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_jobs\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_kubectl\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_nix_shell\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_node\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_os\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_php\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_private_mode\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_pulumi\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_python\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_ruby\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_rustc\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_shlvl\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_status\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_terraform\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_time\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_toolbox\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_vi_mode\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_item_zig\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_parent_dirs\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_print_item\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_pwd\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_remove_unusable_items\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_sub_bug\x2dreport\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_sub_configure\x2efish\x1e\x7e/\x2econfig/fish/functions/_tide_sub_reload\x2efish\x1e\x7e/\x2econfig/fish/functions/fish_mode_prompt\x2efish\x1e\x7e/\x2econfig/fish/functions/fish_prompt\x2efish\x1e\x7e/\x2econfig/fish/functions/tide\x1e\x7e/\x2econfig/fish/functions/tide\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/_tide_init\x2efish\x1e\x7e/\x2econfig/fish/completions/tide\x2efish
|
||||
SETUVAR _fisher_jethrokuan_2F_z_files:\x7e/\x2econfig/fish/functions/__z\x2efish\x1e\x7e/\x2econfig/fish/functions/__z_add\x2efish\x1e\x7e/\x2econfig/fish/functions/__z_clean\x2efish\x1e\x7e/\x2econfig/fish/functions/__z_complete\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/z\x2efish
|
||||
SETUVAR _fisher_jorgebucaran_2F_autopair_2E_fish_files:\x7e/\x2econfig/fish/functions/_autopair_backspace\x2efish\x1e\x7e/\x2econfig/fish/functions/_autopair_insert_left\x2efish\x1e\x7e/\x2econfig/fish/functions/_autopair_insert_right\x2efish\x1e\x7e/\x2econfig/fish/functions/_autopair_insert_same\x2efish\x1e\x7e/\x2econfig/fish/functions/_autopair_tab\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/autopair\x2efish
|
||||
SETUVAR _fisher_jorgebucaran_2F_fisher_files:\x7e/\x2econfig/fish/functions/fisher\x2efish\x1e\x7e/\x2econfig/fish/completions/fisher\x2efish
|
||||
SETUVAR _fisher_plugins:jorgebucaran/fisher\x1eilancosman/tide\x40v6\x1ejethrokuan/z
|
||||
SETUVAR _fisher_plugins:jorgebucaran/fisher\x1eilancosman/tide\x40v6\x1ejethrokuan/z\x1ejorgebucaran/autopair\x2efish
|
||||
SETUVAR _fisher_upgraded_to_4_4:\x1d
|
||||
SETUVAR _tide_left_items:os\x1epwd\x1egit\x1enewline\x1echaracter
|
||||
SETUVAR _tide_prompt_727883:\x1b\x28B\x1b\x5bm\x1b\x28B\x1b\x5bm\x1b\x5b38\x3b5\x3b238m\ue0b2\x1b\x5b38\x3b5\x3b255m\x1b\x5b48\x3b5\x3b238m\x20\uf31b\x20\x1b\x5b38\x3b5\x3b246m\ue0b1\x1b\x5b48\x3b5\x3b238m\x20\x40PWD\x40\x20\x1b\x28B\x1b\x5bm\x1b\x28B\x1b\x5bm\x1b\x5b38\x3b5\x3b238m\ue0b0\x1e\x1b\x5b38\x3b5\x3b196m\u276f\x1e\x1b\x28B\x1b\x5bm\x1b\x28B\x1b\x5bm\x1b\x5b38\x3b5\x3b238m\ue0b2\x1b\x5b38\x3b5\x3b66m\x1b\x5b48\x3b5\x3b238m\x2012\x3a38\x3a18\x20\x1b\x28B\x1b\x5bm\x1b\x28B\x1b\x5bm\x1b\x5b38\x3b5\x3b238m\ue0b0
|
||||
|
9
fish/.config/fish/functions/_autopair_backspace.fish
Normal file
9
fish/.config/fish/functions/_autopair_backspace.fish
Normal file
@ -0,0 +1,9 @@
|
||||
function _autopair_backspace
|
||||
set --local index (commandline --cursor)
|
||||
set --local buffer (commandline)
|
||||
|
||||
test $index -ge 1 &&
|
||||
contains -- (string sub --start=$index --length=2 -- "$buffer") $autopair_pairs &&
|
||||
commandline --function delete-char
|
||||
commandline --function backward-delete-char
|
||||
end
|
13
fish/.config/fish/functions/_autopair_insert_left.fish
Normal file
13
fish/.config/fish/functions/_autopair_insert_left.fish
Normal file
@ -0,0 +1,13 @@
|
||||
function _autopair_insert_left --argument-names left right
|
||||
set --local buffer (commandline)
|
||||
set --local before (commandline --cut-at-cursor)
|
||||
|
||||
commandline --insert -- $left
|
||||
|
||||
switch "$buffer"
|
||||
case "$before"{," "\*,$autopair_right\*}
|
||||
set --local index (commandline --cursor)
|
||||
commandline --insert -- $right
|
||||
commandline --cursor $index
|
||||
end
|
||||
end
|
11
fish/.config/fish/functions/_autopair_insert_right.fish
Normal file
11
fish/.config/fish/functions/_autopair_insert_right.fish
Normal file
@ -0,0 +1,11 @@
|
||||
function _autopair_insert_right --argument-names key
|
||||
set --local buffer (commandline)
|
||||
set --local before (commandline --cut-at-cursor)
|
||||
|
||||
switch "$buffer"
|
||||
case "$before$key"\*
|
||||
commandline --cursor (math (commandline --cursor) + 1)
|
||||
case \*
|
||||
commandline --insert -- $key
|
||||
end
|
||||
end
|
20
fish/.config/fish/functions/_autopair_insert_same.fish
Normal file
20
fish/.config/fish/functions/_autopair_insert_same.fish
Normal file
@ -0,0 +1,20 @@
|
||||
function _autopair_insert_same --argument-names key
|
||||
set --local buffer (commandline)
|
||||
set --local index (commandline --cursor)
|
||||
set --local next (string sub --start=(math $index + 1) --length=1 -- "$buffer")
|
||||
|
||||
if test (math (count (string match --all --regex -- "$key" "$buffer")) % 2) = 0
|
||||
test $key = $next && commandline --cursor (math $index + 1) && return
|
||||
|
||||
commandline --insert -- $key
|
||||
|
||||
if test $index -lt 1 ||
|
||||
contains -- (string sub --start=$index --length=1 -- "$buffer") "" " " $autopair_left &&
|
||||
contains -- $next "" " " $autopair_right
|
||||
commandline --insert -- $key
|
||||
commandline --cursor (math $index + 1)
|
||||
end
|
||||
else
|
||||
commandline --insert -- $key
|
||||
end
|
||||
end
|
7
fish/.config/fish/functions/_autopair_tab.fish
Normal file
7
fish/.config/fish/functions/_autopair_tab.fish
Normal file
@ -0,0 +1,7 @@
|
||||
function _autopair_tab
|
||||
commandline --paging-mode && down-or-search && return
|
||||
|
||||
string match --quiet --regex -- '\$[^\s]*"$' (commandline --current-token) &&
|
||||
commandline --function end-of-line --function backward-delete-char
|
||||
commandline --function complete
|
||||
end
|
Loading…
Reference in New Issue
Block a user