Update fish

This commit is contained in:
Hydroxycarbamide 2023-04-03 16:40:39 +02:00
parent f5306476ea
commit 123172a72b
16 changed files with 382 additions and 41 deletions

View file

@ -0,0 +1,30 @@
# helper for _fzf_search_git_status
# arg should be a line from git status --short, e.g.
# MM functions/_fzf_preview_changed_file.fish
# D README.md
# R LICENSE.md -> LICENSE
function _fzf_preview_changed_file --description "Show the untracked, staged, and/or unstaged changes in the given file."
set -l path (string split ' ' $argv)[-1]
# first letter of short format shows index, second letter shows working tree
# https://git-scm.com/docs/git-status/2.35.0#_output
set -l index_status (string sub --length 1 $argv)
set -l working_tree_status (string sub --start 2 --length 1 $argv)
if test $index_status = '?'
_fzf_report_diff_type Untracked
_fzf_preview_file $path
else
# no-prefix because the file is always being compared to itself so is unecessary
set diff_opts --color=always --no-prefix
if test $index_status != ' '
_fzf_report_diff_type Staged
git diff --staged $diff_opts -- $path
end
if test $working_tree_status != ' '
_fzf_report_diff_type Unstaged
git diff $diff_opts -- $path
end
end
end

View file

@ -1,4 +1,4 @@
# helper function for _fzf_search_directory
# helper function for _fzf_search_directory and _fzf_search_git_status
function _fzf_preview_file --description "Print a preview for the given file based on its file type."
# because there's no way to guarantee that _fzf_search_directory passes the path to _fzf_preview_file
# as one argument, we collect all the arguments into one single variable and treat that as the path

View file

@ -0,0 +1,16 @@
# helper for _fzf_preview_changed_file
# prints out something like
# +--------+
# | Staged |
# +--------+
function _fzf_report_diff_type --argument-names diff_type --description "Print a distinct colored header meant to preface a git patch."
# number of "-" to draw is the length of the string to box + 2 for padding
set repeat_count (math 2 + (string length $diff_type))
set horizontal_border +(string repeat --count $repeat_count -)+
set_color yellow
echo $horizontal_border
echo "| $diff_type |"
echo $horizontal_border
set_color normal
end

View file

@ -31,7 +31,8 @@ function _fzf_search_directory --description "Search the current directory. Repl
# Then, the user only needs to hit Enter once more to cd into that directory.
if test (count $file_paths_selected) = 1
set commandline_tokens (commandline --tokenize)
if test "$commandline_tokens" = "$token" -a -d "$file_paths_selected"
if test "$commandline_tokens" = "$token" -a -d "$file_paths_selected" \
-a (fd --version | string replace --regex --all '[^\d]' '') -lt 840
set file_paths_selected $file_paths_selected/
end
end

View file

@ -8,6 +8,7 @@ function _fzf_search_git_status --description "Search the output of git status.
_fzf_wrapper --ansi \
--multi \
--query=(commandline --current-token) \
--preview='_fzf_preview_changed_file {}' \
$fzf_git_status_opts
)
if test $status -eq 0

View file

@ -1,23 +1,29 @@
function _fzf_search_history --description "Search command history. Replace the command line with the selected command."
# history merge incorporates history changes from other fish sessions
builtin history merge
# it errors out if called in private mode
if test -z "$fish_private_mode"
builtin history merge
end
set command_with_ts (
# Delinate commands throughout pipeline using null rather than newlines because commands can be multi-line
set commands_selected (
# Reference https://devhints.io/strftime to understand strftime format symbols
builtin history --null --show-time="%m-%d %H:%M:%S │ " |
_fzf_wrapper --read0 \
--print0 \
--multi \
--tiebreak=index \
--query=(commandline) \
# preview current command using fish_ident in a window at the bottom 3 lines tall
--preview="echo -- {4..} | fish_indent --ansi" \
--preview-window="bottom:3:wrap" \
$fzf_history_opts |
string collect
string split0 |
# remove timestamps from commands selected
string replace --regex '^\d\d-\d\d \d\d:\d\d:\d\d │ ' ''
)
if test $status -eq 0
set command_selected (string split --max 1 " │ " $command_with_ts)[2]
commandline --replace -- $command_selected
commandline --replace -- $commands_selected
end
commandline --function repaint

41
functions/man.fish Normal file
View file

@ -0,0 +1,41 @@
function man --wraps man --description 'Format and display manual pages'
set -q man_blink; and set -l blink (set_color $man_blink); or set -l blink (set_color -o red)
set -q man_bold; and set -l bold (set_color $man_bold); or set -l bold (set_color -o 5fafd7)
set -q man_standout; and set -l standout (set_color $man_standout); or set -l standout (set_color 949494)
set -q man_underline; and set -l underline (set_color $man_underline); or set -l underline (set_color -u afafd7)
set -l end (printf "\e[0m")
set -lx LESS_TERMCAP_mb $blink
set -lx LESS_TERMCAP_md $bold
set -lx LESS_TERMCAP_me $end
set -lx LESS_TERMCAP_so $standout
set -lx LESS_TERMCAP_se $end
set -lx LESS_TERMCAP_us $underline
set -lx LESS_TERMCAP_ue $end
set -lx LESS '-R -s'
set -lx GROFF_NO_SGR yes # fedora
set -lx MANPATH (string join : $MANPATH)
if test -z "$MANPATH"
type -q manpath
and set MANPATH (command manpath)
end
# Check data dir for Fish 2.x compatibility
set -l fish_data_dir
if set -q __fish_data_dir
set fish_data_dir $__fish_data_dir
else
set fish_data_dir $__fish_datadir
end
set -l fish_manpath (dirname $fish_data_dir)/fish/man
if test -d "$fish_manpath" -a -n "$MANPATH"
set MANPATH "$fish_manpath":$MANPATH
command man $argv
return
end
command man $argv
end

53
functions/nvm.fish Normal file
View file

@ -0,0 +1,53 @@
function nvm-fast
set -q NVM_DIR ; or set -l NVM_DIR ~/.nvm
set -l brigand_nvm_fish_path $NVM_DIR/versions/node
if test (count $argv[1]) -lt 1
echo 'nvm-fast: at least one argument is required'
end
set -l command $argv[1]
if test $command = 'use'
set target_version "unknown"
if test (count $argv) -eq 1
if test -f .nvmrc
set target_version (cat .nvmrc)
else
echo "Error: No version provided and no .nvmrc found"
return
end
else
set target_version $argv[2]
end
set -l target_version $target_version
set -l matched_version (bash -c "source $NVM_DIR/nvm.sh --no-use; nvm_version $target_version")
if test -z $matched_version -o $matched_version = 'N/A'
echo "No version installed for $target_version, run nvm install $target_version"
echo "Installed versions: "
for file in $brigand_nvm_fish_path/v*
echo ' -' $file
end
else
set -l new_path (string match -ev "$brigand_nvm_fish_path" $PATH)
if test $matched_version != 'system'
set new_path $brigand_nvm_fish_path/$matched_version/bin $new_path
end
set -gx PATH $new_path
set -gx NVM_BIN (which node)
end
else
bash -c "source $NVM_DIR/nvm.sh --no-use; nvm $argv"
set -gx NVM_BIN (which node)
end
end
function nvm
switch "$FISH_VERSION"
case 2.0.0 2.1.0 2.1.1 2.1.2 2.2.0 2.2b1 2.3.0 2.3.1 2.3b1 2.3b2 2.4.0 2.4b1 2.5.0 2.5b1
echo "You need fish 2.6.0 or higher to use fast-nvm-fish." 1>&2
return 1
end
nvm-fast $argv
end