AutoYADM commit: 2025-03-28 18:45:08
This commit is contained in:
parent
393973db39
commit
4606237776
78 changed files with 2856 additions and 1 deletions
20
.config/fish/functions/__gitnow_check_if_branch_exist.fish
Normal file
20
.config/fish/functions/__gitnow_check_if_branch_exist.fish
Normal file
|
@ -0,0 +1,20 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_check_if_branch_exist
|
||||
set -l xfound 0
|
||||
|
||||
if test (count $argv) -eq 1
|
||||
set -l xbranch $argv[1]
|
||||
set -l xbranch_list (__gitnow_current_branch_list)
|
||||
|
||||
for b in $xbranch_list
|
||||
if [ "$xbranch" = "$b" ]
|
||||
set xfound 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
echo $xfound
|
||||
end
|
17
.config/fish/functions/__gitnow_clone_msg.fish
Normal file
17
.config/fish/functions/__gitnow_clone_msg.fish
Normal file
|
@ -0,0 +1,17 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_clone_msg
|
||||
set -l msg $argv[1]
|
||||
|
||||
echo "Repository name is required!"
|
||||
echo "Example: $msg your-repo-name"
|
||||
echo "Usages:"
|
||||
echo " a) $msg username/repo-name"
|
||||
echo " b) $msg username repo-name"
|
||||
echo " c) $msg repo-name"
|
||||
echo " For this, it's necessary to set your $msg username (login)"
|
||||
echo " to global config before like: "
|
||||
echo " git config --global user.$msg \"your-username\""
|
||||
echo
|
||||
end
|
18
.config/fish/functions/__gitnow_clone_params.fish
Normal file
18
.config/fish/functions/__gitnow_clone_params.fish
Normal file
|
@ -0,0 +1,18 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_clone_params
|
||||
set -l repo
|
||||
|
||||
if count $argv >/dev/null
|
||||
if test (count $argv) -gt 1
|
||||
set repo $argv[1]/$argv[2]
|
||||
else if echo $argv | LC_ALL=C command grep -q -E '^([a-zA-Z0-9\_\-]+)\/([a-zA-Z0-9\_\-]+)$'
|
||||
set repo $argv
|
||||
else
|
||||
set repo "%S/$argv"
|
||||
end
|
||||
end
|
||||
|
||||
echo $repo
|
||||
end
|
41
.config/fish/functions/__gitnow_clone_repo.fish
Normal file
41
.config/fish/functions/__gitnow_clone_repo.fish
Normal file
|
@ -0,0 +1,41 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_clone_repo
|
||||
set -l repo $argv[1]
|
||||
set -l platform $argv[2]
|
||||
|
||||
if test -n "$repo"
|
||||
set -l ok 1
|
||||
|
||||
if echo $repo | LC_ALL=C command grep -q -E '^[\%S].+'
|
||||
set -l user (command git config --global user.$platform)
|
||||
|
||||
if test -n "$user"
|
||||
set -l repor (echo $repo | LC_ALL=C command sed -e "s/^%S/$user/")
|
||||
set repo $repor
|
||||
else
|
||||
set ok 0
|
||||
end
|
||||
end
|
||||
|
||||
if test $ok -eq 1
|
||||
if [ "$platform" = "github" ]
|
||||
set url github.com
|
||||
end
|
||||
|
||||
if [ "$platform" = "bitbucket" ]
|
||||
set url bitbucket.org
|
||||
end
|
||||
|
||||
set -l repo_url git@$url:$repo.git
|
||||
|
||||
echo "📦 Remote repository: $repo_url"
|
||||
command git clone $repo_url
|
||||
else
|
||||
__gitnow_clone_msg $platform
|
||||
end
|
||||
else
|
||||
__gitnow_clone_msg $platform
|
||||
end
|
||||
end
|
6
.config/fish/functions/__gitnow_current_branch_list.fish
Normal file
6
.config/fish/functions/__gitnow_current_branch_list.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_current_branch_list
|
||||
command git branch --list --no-color | LC_ALL=C command sed -E "s/^(\*?[ \t]*)//g" 2>/dev/null
|
||||
end
|
6
.config/fish/functions/__gitnow_current_branch_name.fish
Normal file
6
.config/fish/functions/__gitnow_current_branch_name.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_current_branch_name
|
||||
command git symbolic-ref --short HEAD 2>/dev/null
|
||||
end
|
7
.config/fish/functions/__gitnow_current_remote.fish
Normal file
7
.config/fish/functions/__gitnow_current_remote.fish
Normal file
|
@ -0,0 +1,7 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_current_remote
|
||||
set -l branch_name (__gitnow_current_branch_name)
|
||||
command git config "branch.$branch_name.remote" 2>/dev/null; or echo origin
|
||||
end
|
18
.config/fish/functions/__gitnow_get_clip_program.fish
Normal file
18
.config/fish/functions/__gitnow_get_clip_program.fish
Normal file
|
@ -0,0 +1,18 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_get_clip_program -d "Gets the current clip installed program"
|
||||
set -l v_paste
|
||||
|
||||
if type -q xclip
|
||||
set v_paste "xclip -selection clipboard -o"
|
||||
else if type -q wl-clipboard
|
||||
set v_paste "wl-paste"
|
||||
else if type -q xsel
|
||||
set v_paste "xsel --clipboard --output"
|
||||
else if type -q pbpaste
|
||||
set v_paste "pbpaste"
|
||||
end
|
||||
|
||||
echo -n $v_paste
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_get_latest_semver_release_tag
|
||||
for tg in (__gitnow_get_tags_ordered)
|
||||
if echo $tg | LC_ALL=C command grep -qE '^v?([0-9]+).([0-9]+).([0-9]+)$'
|
||||
echo $tg 2>/dev/null
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
6
.config/fish/functions/__gitnow_get_latest_tag.fish
Normal file
6
.config/fish/functions/__gitnow_get_latest_tag.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_get_latest_tag
|
||||
command git tag --sort=-creatordate | head -n1 2>/dev/null
|
||||
end
|
8
.config/fish/functions/__gitnow_get_tags_ordered.fish
Normal file
8
.config/fish/functions/__gitnow_get_tags_ordered.fish
Normal file
|
@ -0,0 +1,8 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
# lexicographic order and tag names treated as versions
|
||||
# https://stackoverflow.com/a/52680984/2510591
|
||||
function __gitnow_get_tags_ordered
|
||||
command git -c 'versionsort.suffix=-' tag --list --sort=-version:refname
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_get_valid_semver_prerelease_value -a tagv
|
||||
command echo $tagv | LC_ALL=C command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]-[a-zA-Z0-9\-_.]*\)\([}]*\)/\1/p' 2>/dev/null
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_get_valid_semver_release_value -a tagv
|
||||
command echo $tagv | LC_ALL=C command sed -n 's/^v\\{0,1\\}\([0-9].[0-9].[0-9]*\)\([}]*\)/\1/p' 2>/dev/null
|
||||
end
|
16
.config/fish/functions/__gitnow_gitflow_branch.fish
Normal file
16
.config/fish/functions/__gitnow_gitflow_branch.fish
Normal file
|
@ -0,0 +1,16 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_gitflow_branch -a xprefix -a xbranch
|
||||
set xbranch (__gitnow_slugify $xbranch)
|
||||
set -l xbranch_full "$xprefix/$xbranch"
|
||||
set -l xfound (__gitnow_check_if_branch_exist $xbranch_full)
|
||||
|
||||
if test $xfound -eq 1
|
||||
echo "Branch `$xbranch_full` already exists. Nothing to do."
|
||||
else
|
||||
command git stash
|
||||
__gitnow_new_branch_switch "$xbranch_full"
|
||||
command git stash pop
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_has_uncommited_changes
|
||||
command git diff-index --quiet HEAD -- || echo "1" 2>&1
|
||||
end
|
12
.config/fish/functions/__gitnow_increment_number.fish
Normal file
12
.config/fish/functions/__gitnow_increment_number.fish
Normal file
|
@ -0,0 +1,12 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_increment_number -a strv
|
||||
command echo $strv | LC_ALL=C command awk '
|
||||
function increment(val) {
|
||||
if (val ~ /[0-9]+/) { return val + 1 }
|
||||
return val
|
||||
}
|
||||
{ print increment($0) }
|
||||
' 2>/dev/null
|
||||
end
|
6
.config/fish/functions/__gitnow_is_git_repository.fish
Normal file
6
.config/fish/functions/__gitnow_is_git_repository.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_is_git_repository
|
||||
command git rev-parse --git-dir >/dev/null 2>&1
|
||||
end
|
6
.config/fish/functions/__gitnow_is_number.fish
Normal file
6
.config/fish/functions/__gitnow_is_number.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_is_number -a strv
|
||||
command echo -n $strv | LC_ALL=C command grep -qE '^([0-9]+)$'
|
||||
end
|
180
.config/fish/functions/__gitnow_load_config.fish
Normal file
180
.config/fish/functions/__gitnow_load_config.fish
Normal file
|
@ -0,0 +1,180 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_load_config -d "Reads the GitNow configuration file"
|
||||
# Sets a clipboard program
|
||||
set g_xpaste (__gitnow_get_clip_program)
|
||||
|
||||
# Config file path used by default
|
||||
set -l config_file "$fish_snippets/.gitnow"
|
||||
|
||||
# Download the default `.gitnow` file.
|
||||
# NOTE: this is only used as a workaround for Fisher.
|
||||
# See https://github.com/jorgebucaran/fisher/pull/573
|
||||
if not test -e $config_file
|
||||
curl -sSo $config_file https://raw.githubusercontent.com/joseluisq/gitnow/master/conf.d/.gitnow
|
||||
end
|
||||
|
||||
# Prefer custom config file if it exists
|
||||
if test -e $GITNOW_CONFIG_FILE
|
||||
set config_file $GITNOW_CONFIG_FILE
|
||||
else if not test -e $config_file
|
||||
# Otherwise checks if default `.gitnow` file exists,
|
||||
# if doesn't exist then skip out file parsing
|
||||
return
|
||||
end
|
||||
|
||||
# Parse `.gitnow` file content
|
||||
|
||||
# 2 = keybindings
|
||||
# 3 = options
|
||||
set -l v_section 0
|
||||
|
||||
# Valid sections
|
||||
set -l v_keybindings "keybindings"
|
||||
set -l v_options "options"
|
||||
|
||||
# Options set
|
||||
set -l v_clipboard 0
|
||||
|
||||
# Loop every line
|
||||
while read -la l
|
||||
set -l v_str ""
|
||||
set -l v_comment 0
|
||||
set -l v_command_sep 0
|
||||
set -l v_command_key ""
|
||||
set -l v_command_val ""
|
||||
|
||||
# Loop every char for current line
|
||||
echo $l | while read -n 1 -la c;
|
||||
switch $c
|
||||
case '['
|
||||
if test $v_comment -eq 1; continue; end
|
||||
|
||||
# if test $v_section -gt 0
|
||||
# set v_section 0
|
||||
# continue
|
||||
# end
|
||||
|
||||
# Start section
|
||||
if test $v_section -eq 0; set v_section 1; end
|
||||
case ']'
|
||||
if test $v_comment -eq 1; continue; end
|
||||
|
||||
# Check section name
|
||||
if test $v_section -eq 1
|
||||
# options
|
||||
if [ "$v_str" = "$v_options" ]
|
||||
set v_section 3
|
||||
continue
|
||||
end
|
||||
|
||||
# keybindings
|
||||
if [ "$v_str" = "$v_keybindings" ]
|
||||
set v_section 2
|
||||
continue
|
||||
end
|
||||
end
|
||||
|
||||
set v_section 0
|
||||
case ' '
|
||||
case '\n'
|
||||
case '\t'
|
||||
case '\r'
|
||||
continue
|
||||
case '#'
|
||||
if test $v_comment -eq 0; set v_comment 1; end
|
||||
continue
|
||||
case '*'
|
||||
if test $v_comment -eq 1; continue; end
|
||||
|
||||
# If section has started then accumulate chars and continue
|
||||
if test $v_section -eq 1
|
||||
set v_str "$v_str$c"
|
||||
continue
|
||||
end
|
||||
|
||||
# A [ abcde ] section is found so proceed with chars handling
|
||||
# NOTE: only alphabetic and hyphens chars are allowed
|
||||
if test $v_section -eq 2; or test $v_section -eq 3
|
||||
switch $c
|
||||
case 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '-'
|
||||
if test $v_command_sep -eq 0
|
||||
set v_command_key "$v_command_key$c"
|
||||
continue
|
||||
end
|
||||
|
||||
if test $v_command_sep -eq 2
|
||||
set v_command_val "$v_command_val$c"
|
||||
continue
|
||||
end
|
||||
case \\
|
||||
if test $v_command_sep -eq 1
|
||||
set v_command_sep 2
|
||||
end
|
||||
continue
|
||||
case '='
|
||||
set v_command_sep 1
|
||||
if test $v_section -eq 3
|
||||
set v_command_sep 2
|
||||
continue
|
||||
end
|
||||
case '*'
|
||||
continue
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 1. Handle options set
|
||||
if test $v_section -eq 3
|
||||
switch $v_command_key
|
||||
# Clipboard option
|
||||
case 'clipboard'
|
||||
if [ "$v_command_val" = "true" ]
|
||||
set v_clipboard 1
|
||||
end
|
||||
# NOTE: handle future new options using a new case
|
||||
case '*'
|
||||
continue
|
||||
end
|
||||
# continue loop after current option processed
|
||||
set v_section 0
|
||||
continue
|
||||
end
|
||||
|
||||
# 2. Handle keybindings set
|
||||
if not [ "$v_command_key" = "" ]; and not [ "$v_command_val" = "" ]
|
||||
set -l cmd
|
||||
|
||||
switch $v_command_key
|
||||
case 'release' 'hotfix' 'feature' 'bugfix'
|
||||
# Read text from clipboard if there is a valid clipboard program
|
||||
# and if the "clipboard" option is "true"
|
||||
if test -n $g_xpaste; and test $v_clipboard -eq 1
|
||||
set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key ($g_xpaste); commandline -f repaint; else ; end\"")
|
||||
else
|
||||
# Otherwise read text from standard input
|
||||
set cmd (echo -n "bind \\$v_command_val \"echo; if $v_command_key (read); commandline -f repaint; else ; end\"")
|
||||
end
|
||||
case '*'
|
||||
# Check command key against a list of valid commands
|
||||
set -l v_valid 0
|
||||
for v in $gitnow_commands
|
||||
if [ "$v" = "$v_command_key" ]
|
||||
set v_valid 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# If command key is not valid then just skip out
|
||||
if test $v_valid -eq 0; continue; end
|
||||
|
||||
set cmd (echo -n "bind \\$v_command_val \"echo; $v_command_key; commandline -f repaint;\"")
|
||||
end
|
||||
|
||||
eval $cmd
|
||||
end
|
||||
|
||||
end < $config_file
|
||||
end
|
8
.config/fish/functions/__gitnow_load_git_functions.fish
Normal file
8
.config/fish/functions/__gitnow_load_git_functions.fish
Normal file
|
@ -0,0 +1,8 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_load_git_functions -d "Gitnow: Load fish git functions on demand"
|
||||
if begin not type -q __fish_git_branches; or not type -q __fish_git_tags; end
|
||||
source $__fish_data_dir/completions/git.fish
|
||||
end
|
||||
end
|
115
.config/fish/functions/__gitnow_manual.fish
Normal file
115
.config/fish/functions/__gitnow_manual.fish
Normal file
|
@ -0,0 +1,115 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_manual -d "Gitnow: Manual page like"
|
||||
echo (set_color --bold)"NAME"(set_color normal)
|
||||
echo " GitNow — Speed up your Git workflow. 🐠"
|
||||
echo
|
||||
echo (set_color --bold)"VERSION"(set_color normal)
|
||||
echo " $gitnow_version"
|
||||
echo
|
||||
echo (set_color --bold)"DESCRIPTION"(set_color normal)
|
||||
echo " GitNow contains a rich command set that provides high-level operations on the top of Git(1)."
|
||||
echo " A Fish Shell(2) alternative inspired by git-friendly(3)."
|
||||
echo
|
||||
echo " (1) https://git-scm.com/"
|
||||
echo " (2) https://fishshell.com/"
|
||||
echo " (3) https://github.com/jamiew/git-friendly"
|
||||
echo
|
||||
echo (set_color --bold)"COMMANDS"(set_color normal)
|
||||
echo " "(set_color --bold)"state"(set_color normal)
|
||||
echo " Show the working tree status in a compact way."
|
||||
echo
|
||||
echo " "(set_color --bold)"stage"(set_color normal)
|
||||
echo " Stage files in the current working directory."
|
||||
echo
|
||||
echo " "(set_color --bold)"unstage"(set_color normal)
|
||||
echo " Unstage files in the current working directory."
|
||||
echo
|
||||
echo " "(set_color --bold)"show"(set_color normal)
|
||||
echo " Show commit detail objects."
|
||||
echo
|
||||
echo " "(set_color --bold)"untracked"(set_color normal)
|
||||
echo " Check for untracked files and directories that could be removed."
|
||||
echo
|
||||
echo " "(set_color --bold)"commit"(set_color normal)
|
||||
echo " Commit changes to the current repository."
|
||||
echo
|
||||
echo " "(set_color --bold)"commit-all"(set_color normal)
|
||||
echo " Add and commit all changes to the current repository."
|
||||
echo
|
||||
echo " "(set_color --bold)"pull"(set_color normal)
|
||||
echo " Pull changes from remote server but auto-stashing uncommitted changes."
|
||||
echo
|
||||
echo " "(set_color --bold)"push"(set_color normal)
|
||||
echo " Push commit changes to the current remote repository."
|
||||
echo
|
||||
echo " "(set_color --bold)"upstream"(set_color normal)
|
||||
echo " Commit all changes and push them to the current remote server."
|
||||
echo
|
||||
echo " "(set_color --bold)"move"(set_color normal)
|
||||
echo " Switch from current branch to another but stashing uncommitted changes."
|
||||
echo
|
||||
echo " "(set_color --bold)"merge"(set_color normal)
|
||||
echo " Merge given branch into the active one"
|
||||
echo
|
||||
echo " "(set_color --bold)"tag"(set_color normal)
|
||||
echo " List and create release tag versions following Semver 2.0."
|
||||
echo
|
||||
echo " "(set_color --bold)"assume"(set_color normal)
|
||||
echo " Ignore changes in certain files temporarily."
|
||||
echo
|
||||
echo " "(set_color --bold)"feature"(set_color normal)
|
||||
echo " Create a new Gitflow feature branch from the current branch."
|
||||
echo
|
||||
echo " "(set_color --bold)"hotfix"(set_color normal)
|
||||
echo " Create a new Gitflow hotfix branch from the current branch."
|
||||
echo
|
||||
echo " "(set_color --bold)"bugfix"(set_color normal)
|
||||
echo " Create a new Gitflow bugfix branch from the current branch."
|
||||
echo
|
||||
echo " "(set_color --bold)"release"(set_color normal)
|
||||
echo " Create a new Gitflow release branch from the current branch."
|
||||
echo
|
||||
echo " "(set_color --bold)"logs"(set_color normal)
|
||||
echo " Show logs in a fancy way."
|
||||
echo
|
||||
echo " "(set_color --bold)"github"(set_color normal)
|
||||
echo " Clone a GitHub repository over SSH."
|
||||
echo
|
||||
echo " "(set_color --bold)"bitbucket"(set_color normal)
|
||||
echo " Clone a Bitbucket Cloud repository over SSH."
|
||||
echo
|
||||
echo (set_color --bold)"KEYBINDINGS"(set_color normal)
|
||||
echo " state Alt + S"
|
||||
echo " stage Alt + E"
|
||||
echo " unstage Ctrl + E"
|
||||
echo " show Alt + M"
|
||||
echo " commit-all Alt + C"
|
||||
echo " pull Alt + D"
|
||||
echo " push Alt + P"
|
||||
echo " upstream Alt + U"
|
||||
echo " feature(1) Alt + F"
|
||||
echo " hotfix(1) Alt + H"
|
||||
echo " logs Alt + L"
|
||||
echo
|
||||
echo " (1) This command key binding will creates a new branch taking as name some text of the clipboard."
|
||||
echo
|
||||
echo (set_color --bold)"CONFIGURATION"(set_color normal)
|
||||
echo " For a custom configuration (for example keybindings) place a "(set_color --bold)"~/.gitnow"(set_color normal)" file (1) in your home directory."
|
||||
echo
|
||||
echo " (1) An example file it can be found on "(set_color --bold)https://github.com/joseluisq/gitnow/tree/master/.gitnow(set_color normal)
|
||||
echo
|
||||
echo (set_color --bold)"FURTHER DOCUMENTATION"(set_color normal)
|
||||
echo " For more details and examples check out "(set_color --bold)https://github.com/joseluisq/gitnow/blob/master/README.md(set_color normal)
|
||||
echo
|
||||
echo (set_color --bold)"CONTRIBUTIONS"(set_color normal)
|
||||
echo " Send bug reports or pull requests to "(set_color --bold)https://github.com/joseluisq/gitnow(set_color normal)
|
||||
echo
|
||||
echo (set_color --bold)"LICENSE"(set_color normal)
|
||||
echo " GitNow licensed under the MIT License "(set_color --bold)https://github.com/joseluisq/gitnow/blob/master/LICENSE.md(set_color normal)
|
||||
echo
|
||||
echo (set_color --bold)"AUTHOR"(set_color normal)
|
||||
echo " (c) 2016-present Jose Quintana "(set_color --bold)"https://github.com/joseluisq"(set_color normal)
|
||||
echo
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_msg_not_valid_repository -a cmd
|
||||
echo "Gitnow ($cmd): Current directory is not a valid Git repository."
|
||||
end
|
14
.config/fish/functions/__gitnow_new_branch_switch.fish
Normal file
14
.config/fish/functions/__gitnow_new_branch_switch.fish
Normal file
|
@ -0,0 +1,14 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
function __gitnow_new_branch_switch
|
||||
set -l branch_name $argv[1]
|
||||
|
||||
if test (count $argv) -eq 1
|
||||
set branch_name $branch_name
|
||||
|
||||
command git checkout -b $branch_name
|
||||
else
|
||||
echo "Provide a branch name."
|
||||
end
|
||||
end
|
7
.config/fish/functions/__gitnow_slugify.fish
Normal file
7
.config/fish/functions/__gitnow_slugify.fish
Normal file
|
@ -0,0 +1,7 @@
|
|||
# GitNow — Speed up your Git workflow. 🐠
|
||||
# https://github.com/joseluisq/gitnow
|
||||
|
||||
# adapted from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6
|
||||
function __gitnow_slugify
|
||||
echo $argv | LC_ALL=C command iconv -t ascii//TRANSLIT | LC_ALL=C command sed -E 's/[^a-zA-Z0-9\-]+/_/g' | LC_ALL=C command sed -E 's/^(-|_)+|(-|_)+$//g'
|
||||
end
|
9
.config/fish/functions/_autopair_backspace.fish
Normal file
9
.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
.config/fish/functions/_autopair_insert_left.fish
Normal file
13
.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
.config/fish/functions/_autopair_insert_right.fish
Normal file
11
.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
.config/fish/functions/_autopair_insert_same.fish
Normal file
20
.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
.config/fish/functions/_autopair_tab.fish
Normal file
7
.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
|
43
.config/fish/functions/_fzf_configure_bindings_help.fish
Normal file
43
.config/fish/functions/_fzf_configure_bindings_help.fish
Normal file
|
@ -0,0 +1,43 @@
|
|||
function _fzf_configure_bindings_help --description "Prints the help message for fzf_configure_bindings."
|
||||
echo "\
|
||||
USAGE:
|
||||
fzf_configure_bindings [--COMMAND=[KEY_SEQUENCE]...]
|
||||
|
||||
DESCRIPTION
|
||||
fzf_configure_bindings installs key bindings for fzf.fish's commands and erases any bindings it
|
||||
previously installed. It installs bindings for both default and insert modes. fzf.fish executes
|
||||
it without options on fish startup to install the out-of-the-box key bindings.
|
||||
|
||||
By default, commands are bound to a mnemonic key sequence, shown below. Each command's binding
|
||||
can be configured using a namesake corresponding option:
|
||||
COMMAND | DEFAULT KEY SEQUENCE | CORRESPONDING OPTION
|
||||
Search Directory | Ctrl+Alt+F (F for file) | --directory
|
||||
Search Git Log | Ctrl+Alt+L (L for log) | --git_log
|
||||
Search Git Status | Ctrl+Alt+S (S for status) | --git_status
|
||||
Search History | Ctrl+R (R for reverse) | --history
|
||||
Search Processes | Ctrl+Alt+P (P for process) | --processes
|
||||
Search Variables | Ctrl+V (V for variable) | --variables
|
||||
Override a command's binding by specifying its corresponding option with the desired key
|
||||
sequence. Disable a command's binding by specifying its corresponding option with no value.
|
||||
|
||||
Because fzf_configure_bindings erases bindings it previously installed, it can be cleanly
|
||||
executed multiple times. Once the desired fzf_configure_bindings command has been found, add it
|
||||
to your config.fish in order to persist the customized bindings.
|
||||
|
||||
In terms of validation, fzf_configure_bindings fails if passed unknown options. It expects an
|
||||
equals sign between an option's name and value. However, it does not validate key sequences.
|
||||
|
||||
Pass -h or --help to print this help message and exit.
|
||||
|
||||
EXAMPLES
|
||||
Default bindings but bind Search Directory to Ctrl+F and Search Variables to Ctrl+Alt+V
|
||||
\$ fzf_configure_bindings --directory=\cf --variables=\e\cv
|
||||
Default bindings but disable Search History
|
||||
\$ fzf_configure_bindings --history=
|
||||
An agglomeration of different options
|
||||
\$ fzf_configure_bindings --git_status=\cg --history=\ch --variables= --processes=
|
||||
|
||||
SEE Also
|
||||
To learn more about fish key bindings, see bind(1) and fish_key_reader(1).
|
||||
"
|
||||
end
|
15
.config/fish/functions/_fzf_extract_var_info.fish
Normal file
15
.config/fish/functions/_fzf_extract_var_info.fish
Normal file
|
@ -0,0 +1,15 @@
|
|||
# helper function for _fzf_search_variables
|
||||
function _fzf_extract_var_info --argument-names variable_name set_show_output --description "Extract and reformat lines pertaining to \$variable_name from \$set_show_output."
|
||||
# Extract only the lines about the variable, all of which begin with either
|
||||
# $variable_name: ...or... $variable_name[
|
||||
string match --regex "^\\\$$variable_name(?::|\[).*" <$set_show_output |
|
||||
|
||||
# Strip the variable name prefix, including ": " for scope info lines
|
||||
string replace --regex "^\\\$$variable_name(?:: )?" '' |
|
||||
|
||||
# Distill the lines of values, replacing...
|
||||
# [1]: |value|
|
||||
# ...with...
|
||||
# [1] value
|
||||
string replace --regex ": \|(.*)\|" ' $1'
|
||||
end
|
49
.config/fish/functions/_fzf_preview_changed_file.fish
Normal file
49
.config/fish/functions/_fzf_preview_changed_file.fish
Normal file
|
@ -0,0 +1,49 @@
|
|||
# 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 -> "New License"
|
||||
function _fzf_preview_changed_file --argument-names path_status --description "Show the git diff of the given file."
|
||||
# remove quotes because they'll be interpreted literally by git diff
|
||||
# no need to requote when referencing $path because fish does not perform word splitting
|
||||
# https://fishshell.com/docs/current/fish_for_bash_users.html
|
||||
set -f path (string unescape (string sub --start 4 $path_status))
|
||||
# first letter of short format shows index, second letter shows working tree
|
||||
# https://git-scm.com/docs/git-status/2.35.0#_short_format
|
||||
set -f index_status (string sub --length 1 $path_status)
|
||||
set -f working_tree_status (string sub --start 2 --length 1 $path_status)
|
||||
|
||||
set -f diff_opts --color=always
|
||||
|
||||
if test $index_status = '?'
|
||||
_fzf_report_diff_type Untracked
|
||||
_fzf_preview_file $path
|
||||
else if contains {$index_status}$working_tree_status DD AU UD UA DU AA UU
|
||||
# Unmerged statuses taken directly from git status help's short format table
|
||||
# Unmerged statuses are mutually exclusive with other statuses, so if we see
|
||||
# these, then safe to assume the path is unmerged
|
||||
_fzf_report_diff_type Unmerged
|
||||
git diff $diff_opts -- $path
|
||||
else
|
||||
if test $index_status != ' '
|
||||
_fzf_report_diff_type Staged
|
||||
|
||||
# renames are only detected in the index, never working tree, so only need to test for it here
|
||||
# https://stackoverflow.com/questions/73954214
|
||||
if test $index_status = R
|
||||
# diff the post-rename path with the original path, otherwise the diff will show the entire file as being added
|
||||
set -f orig_and_new_path (string split --max 1 -- ' -> ' $path)
|
||||
git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2]
|
||||
# path currently has the form of "original -> current", so we need to correct it before it's used below
|
||||
set path $orig_and_new_path[2]
|
||||
else
|
||||
git diff --staged $diff_opts -- $path
|
||||
end
|
||||
end
|
||||
|
||||
if test $working_tree_status != ' '
|
||||
_fzf_report_diff_type Unstaged
|
||||
git diff $diff_opts -- $path
|
||||
end
|
||||
end
|
||||
end
|
43
.config/fish/functions/_fzf_preview_file.fish
Normal file
43
.config/fish/functions/_fzf_preview_file.fish
Normal file
|
@ -0,0 +1,43 @@
|
|||
# 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
|
||||
set -f file_path $argv
|
||||
|
||||
if test -L "$file_path" # symlink
|
||||
# notify user and recurse on the target of the symlink, which can be any of these file types
|
||||
set -l target_path (realpath "$file_path")
|
||||
|
||||
set_color yellow
|
||||
echo "'$file_path' is a symlink to '$target_path'."
|
||||
set_color normal
|
||||
|
||||
_fzf_preview_file "$target_path"
|
||||
else if test -f "$file_path" # regular file
|
||||
if set --query fzf_preview_file_cmd
|
||||
# need to escape quotes to make sure eval receives file_path as a single arg
|
||||
eval "$fzf_preview_file_cmd '$file_path'"
|
||||
else
|
||||
bat --style=numbers --color=always "$file_path"
|
||||
end
|
||||
else if test -d "$file_path" # directory
|
||||
if set --query fzf_preview_dir_cmd
|
||||
# see above
|
||||
eval "$fzf_preview_dir_cmd '$file_path'"
|
||||
else
|
||||
# -A list hidden files as well, except for . and ..
|
||||
# -F helps classify files by appending symbols after the file name
|
||||
command ls -A -F "$file_path"
|
||||
end
|
||||
else if test -c "$file_path"
|
||||
_fzf_report_file_type "$file_path" "character device file"
|
||||
else if test -b "$file_path"
|
||||
_fzf_report_file_type "$file_path" "block device file"
|
||||
else if test -S "$file_path"
|
||||
_fzf_report_file_type "$file_path" socket
|
||||
else if test -p "$file_path"
|
||||
_fzf_report_file_type "$file_path" "named pipe"
|
||||
else
|
||||
echo "$file_path doesn't exist." >&2
|
||||
end
|
||||
end
|
18
.config/fish/functions/_fzf_report_diff_type.fish
Normal file
18
.config/fish/functions/_fzf_report_diff_type.fish
Normal file
|
@ -0,0 +1,18 @@
|
|||
# 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 -f repeat_count (math 2 + (string length $diff_type))
|
||||
set -f line (string repeat --count $repeat_count ─)
|
||||
set -f top_border ╭$line╮
|
||||
set -f btm_border ╰$line╯
|
||||
|
||||
set_color yellow
|
||||
echo $top_border
|
||||
echo "│ $diff_type │"
|
||||
echo $btm_border
|
||||
set_color normal
|
||||
end
|
6
.config/fish/functions/_fzf_report_file_type.fish
Normal file
6
.config/fish/functions/_fzf_report_file_type.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
# helper function for _fzf_preview_file
|
||||
function _fzf_report_file_type --argument-names file_path file_type --description "Explain the file type for a file."
|
||||
set_color red
|
||||
echo "Cannot preview '$file_path': it is a $file_type."
|
||||
set_color normal
|
||||
end
|
33
.config/fish/functions/_fzf_search_directory.fish
Normal file
33
.config/fish/functions/_fzf_search_directory.fish
Normal file
|
@ -0,0 +1,33 @@
|
|||
function _fzf_search_directory --description "Search the current directory. Replace the current token with the selected file paths."
|
||||
# Directly use fd binary to avoid output buffering delay caused by a fd alias, if any.
|
||||
# Debian-based distros install fd as fdfind and the fd package is something else, so
|
||||
# check for fdfind first. Fall back to "fd" for a clear error message.
|
||||
set -f fd_cmd (command -v fdfind || command -v fd || echo "fd")
|
||||
set -f --append fd_cmd --color=always $fzf_fd_opts
|
||||
|
||||
set -f fzf_arguments --multi --ansi $fzf_directory_opts
|
||||
set -f token (commandline --current-token)
|
||||
# expand any variables or leading tilde (~) in the token
|
||||
set -f expanded_token (eval echo -- $token)
|
||||
# unescape token because it's already quoted so backslashes will mess up the path
|
||||
set -f unescaped_exp_token (string unescape -- $expanded_token)
|
||||
|
||||
# If the current token is a directory and has a trailing slash,
|
||||
# then use it as fd's base directory.
|
||||
if string match --quiet -- "*/" $unescaped_exp_token && test -d "$unescaped_exp_token"
|
||||
set --append fd_cmd --base-directory=$unescaped_exp_token
|
||||
# use the directory name as fzf's prompt to indicate the search is limited to that directory
|
||||
set --prepend fzf_arguments --prompt="Directory $unescaped_exp_token> " --preview="_fzf_preview_file $expanded_token{}"
|
||||
set -f file_paths_selected $unescaped_exp_token($fd_cmd 2>/dev/null | _fzf_wrapper $fzf_arguments)
|
||||
else
|
||||
set --prepend fzf_arguments --prompt="Directory> " --query="$unescaped_exp_token" --preview='_fzf_preview_file {}'
|
||||
set -f file_paths_selected ($fd_cmd 2>/dev/null | _fzf_wrapper $fzf_arguments)
|
||||
end
|
||||
|
||||
|
||||
if test $status -eq 0
|
||||
commandline --current-token --replace -- (string escape -- $file_paths_selected | string join ' ')
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
36
.config/fish/functions/_fzf_search_git_log.fish
Normal file
36
.config/fish/functions/_fzf_search_git_log.fish
Normal file
|
@ -0,0 +1,36 @@
|
|||
function _fzf_search_git_log --description "Search the output of git log and preview commits. Replace the current token with the selected commit hash."
|
||||
if not git rev-parse --git-dir >/dev/null 2>&1
|
||||
echo '_fzf_search_git_log: Not in a git repository.' >&2
|
||||
else
|
||||
if not set --query fzf_git_log_format
|
||||
# %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
|
||||
set -f fzf_git_log_format '%C(bold blue)%h%C(reset) - %C(cyan)%ad%C(reset) %C(yellow)%d%C(reset) %C(normal)%s%C(reset) %C(dim normal)[%an]%C(reset)'
|
||||
end
|
||||
|
||||
set -f preview_cmd 'git show --color=always --stat --patch {1}'
|
||||
if set --query fzf_diff_highlighter
|
||||
set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
|
||||
end
|
||||
|
||||
set -f selected_log_lines (
|
||||
git log --no-show-signature --color=always --format=format:$fzf_git_log_format --date=short | \
|
||||
_fzf_wrapper --ansi \
|
||||
--multi \
|
||||
--scheme=history \
|
||||
--prompt="Git Log> " \
|
||||
--preview=$preview_cmd \
|
||||
--query=(commandline --current-token) \
|
||||
$fzf_git_log_opts
|
||||
)
|
||||
if test $status -eq 0
|
||||
for line in $selected_log_lines
|
||||
set -f abbreviated_commit_hash (string split --field 1 " " $line)
|
||||
set -f full_commit_hash (git rev-parse $abbreviated_commit_hash)
|
||||
set -f --append commit_hashes $full_commit_hash
|
||||
end
|
||||
commandline --current-token --replace (string join ' ' $commit_hashes)
|
||||
end
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
41
.config/fish/functions/_fzf_search_git_status.fish
Normal file
41
.config/fish/functions/_fzf_search_git_status.fish
Normal file
|
@ -0,0 +1,41 @@
|
|||
function _fzf_search_git_status --description "Search the output of git status. Replace the current token with the selected file paths."
|
||||
if not git rev-parse --git-dir >/dev/null 2>&1
|
||||
echo '_fzf_search_git_status: Not in a git repository.' >&2
|
||||
else
|
||||
set -f preview_cmd '_fzf_preview_changed_file {}'
|
||||
if set --query fzf_diff_highlighter
|
||||
set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
|
||||
end
|
||||
|
||||
set -f selected_paths (
|
||||
# Pass configuration color.status=always to force status to use colors even though output is sent to a pipe
|
||||
git -c color.status=always status --short |
|
||||
_fzf_wrapper --ansi \
|
||||
--multi \
|
||||
--prompt="Git Status> " \
|
||||
--query=(commandline --current-token) \
|
||||
--preview=$preview_cmd \
|
||||
--nth="2.." \
|
||||
$fzf_git_status_opts
|
||||
)
|
||||
if test $status -eq 0
|
||||
# git status --short automatically escapes the paths of most files for us so not going to bother trying to handle
|
||||
# the few edges cases of weird file names that should be extremely rare (e.g. "this;needs;escaping")
|
||||
set -f cleaned_paths
|
||||
|
||||
for path in $selected_paths
|
||||
if test (string sub --length 1 $path) = R
|
||||
# path has been renamed and looks like "R LICENSE -> LICENSE.md"
|
||||
# extract the path to use from after the arrow
|
||||
set --append cleaned_paths (string split -- "-> " $path)[-1]
|
||||
else
|
||||
set --append cleaned_paths (string sub --start=4 $path)
|
||||
end
|
||||
end
|
||||
|
||||
commandline --current-token --replace -- (string join ' ' $cleaned_paths)
|
||||
end
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
39
.config/fish/functions/_fzf_search_history.fish
Normal file
39
.config/fish/functions/_fzf_search_history.fish
Normal file
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
# it errors out if called in private mode
|
||||
if test -z "$fish_private_mode"
|
||||
builtin history merge
|
||||
end
|
||||
|
||||
if not set --query fzf_history_time_format
|
||||
# Reference https://devhints.io/strftime to understand strftime format symbols
|
||||
set -f fzf_history_time_format "%m-%d %H:%M:%S"
|
||||
end
|
||||
|
||||
# Delinate time from command in history entries using the vertical box drawing char (U+2502).
|
||||
# Then, to get raw command from history entries, delete everything up to it. The ? on regex is
|
||||
# necessary to make regex non-greedy so it won't match into commands containing the char.
|
||||
set -f time_prefix_regex '^.*? │ '
|
||||
# Delinate commands throughout pipeline using null rather than newlines because commands can be multi-line
|
||||
set -f commands_selected (
|
||||
builtin history --null --show-time="$fzf_history_time_format │ " |
|
||||
_fzf_wrapper --read0 \
|
||||
--print0 \
|
||||
--multi \
|
||||
--scheme=history \
|
||||
--prompt="History> " \
|
||||
--query=(commandline) \
|
||||
--preview="string replace --regex '$time_prefix_regex' '' -- {} | fish_indent --ansi" \
|
||||
--preview-window="bottom:3:wrap" \
|
||||
$fzf_history_opts |
|
||||
string split0 |
|
||||
# remove timestamps from commands selected
|
||||
string replace --regex $time_prefix_regex ''
|
||||
)
|
||||
|
||||
if test $status -eq 0
|
||||
commandline --replace -- $commands_selected
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
32
.config/fish/functions/_fzf_search_processes.fish
Normal file
32
.config/fish/functions/_fzf_search_processes.fish
Normal file
|
@ -0,0 +1,32 @@
|
|||
function _fzf_search_processes --description "Search all running processes. Replace the current token with the pid of the selected process."
|
||||
# Directly use ps command because it is often aliased to a different command entirely
|
||||
# or with options that dirty the search results and preview output
|
||||
set -f ps_cmd (command -v ps || echo "ps")
|
||||
# use all caps to be consistent with ps default format
|
||||
# snake_case because ps doesn't seem to allow spaces in the field names
|
||||
set -f ps_preview_fmt (string join ',' 'pid' 'ppid=PARENT' 'user' '%cpu' 'rss=RSS_IN_KB' 'start=START_TIME' 'command')
|
||||
set -f processes_selected (
|
||||
$ps_cmd -A -opid,command | \
|
||||
_fzf_wrapper --multi \
|
||||
--prompt="Processes> " \
|
||||
--query (commandline --current-token) \
|
||||
--ansi \
|
||||
# first line outputted by ps is a header, so we need to mark it as so
|
||||
--header-lines=1 \
|
||||
# ps uses exit code 1 if the process was not found, in which case show an message explaining so
|
||||
--preview="$ps_cmd -o '$ps_preview_fmt' -p {1} || echo 'Cannot preview {1} because it exited.'" \
|
||||
--preview-window="bottom:4:wrap" \
|
||||
$fzf_processes_opts
|
||||
)
|
||||
|
||||
if test $status -eq 0
|
||||
for process in $processes_selected
|
||||
set -f --append pids_selected (string split --no-empty --field=1 -- " " $process)
|
||||
end
|
||||
|
||||
# string join to replace the newlines outputted by string split with spaces
|
||||
commandline --current-token --replace -- (string join ' ' $pids_selected)
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
47
.config/fish/functions/_fzf_search_variables.fish
Normal file
47
.config/fish/functions/_fzf_search_variables.fish
Normal file
|
@ -0,0 +1,47 @@
|
|||
# This function expects the following two arguments:
|
||||
# argument 1 = output of (set --show | psub), i.e. a file with the scope info and values of all variables
|
||||
# argument 2 = output of (set --names | psub), i.e. a file with all variable names
|
||||
function _fzf_search_variables --argument-names set_show_output set_names_output --description "Search and preview shell variables. Replace the current token with the selected variable."
|
||||
if test -z "$set_names_output"
|
||||
printf '%s\n' '_fzf_search_variables requires 2 arguments.' >&2
|
||||
|
||||
commandline --function repaint
|
||||
return 22 # 22 means invalid argument in POSIX
|
||||
end
|
||||
|
||||
# Exclude the history variable from being piped into fzf because
|
||||
# 1. it's not included in $set_names_output
|
||||
# 2. it tends to be a very large value => increases computation time
|
||||
# 3._fzf_search_history is a much better way to examine history anyway
|
||||
set -f all_variable_names (string match --invert history <$set_names_output)
|
||||
|
||||
set -f current_token (commandline --current-token)
|
||||
# Use the current token to pre-populate fzf's query. If the current token begins
|
||||
# with a $, remove it from the query so that it will better match the variable names
|
||||
set -f cleaned_curr_token (string replace -- '$' '' $current_token)
|
||||
|
||||
set -f variable_names_selected (
|
||||
printf '%s\n' $all_variable_names |
|
||||
_fzf_wrapper --preview "_fzf_extract_var_info {} $set_show_output" \
|
||||
--prompt="Variables> " \
|
||||
--preview-window="wrap" \
|
||||
--multi \
|
||||
--query=$cleaned_curr_token \
|
||||
$fzf_variables_opts
|
||||
)
|
||||
|
||||
if test $status -eq 0
|
||||
# If the current token begins with a $, do not overwrite the $ when
|
||||
# replacing the current token with the selected variable.
|
||||
# Uses brace expansion to prepend $ to each variable name.
|
||||
commandline --current-token --replace (
|
||||
if string match --quiet -- '$*' $current_token
|
||||
string join " " \${$variable_names_selected}
|
||||
else
|
||||
string join " " $variable_names_selected
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
commandline --function repaint
|
||||
end
|
21
.config/fish/functions/_fzf_wrapper.fish
Normal file
21
.config/fish/functions/_fzf_wrapper.fish
Normal file
|
@ -0,0 +1,21 @@
|
|||
function _fzf_wrapper --description "Prepares some environment variables before executing fzf."
|
||||
# Make sure fzf uses fish to execute preview commands, some of which
|
||||
# are autoloaded fish functions so don't exist in other shells.
|
||||
# Use --function so that it doesn't clobber SHELL outside this function.
|
||||
set -f --export SHELL (command --search fish)
|
||||
|
||||
# If neither FZF_DEFAULT_OPTS nor FZF_DEFAULT_OPTS_FILE are set, then set some sane defaults.
|
||||
# See https://github.com/junegunn/fzf#environment-variables
|
||||
set --query FZF_DEFAULT_OPTS FZF_DEFAULT_OPTS_FILE
|
||||
if test $status -eq 2
|
||||
# cycle allows jumping between the first and last results, making scrolling faster
|
||||
# layout=reverse lists results top to bottom, mimicking the familiar layouts of git log, history, and env
|
||||
# border shows where the fzf window begins and ends
|
||||
# height=90% leaves space to see the current command and some scrollback, maintaining context of work
|
||||
# preview-window=wrap wraps long lines in the preview window, making reading easier
|
||||
# marker=* makes the multi-select marker more distinguishable from the pointer (since both default to >)
|
||||
set --export FZF_DEFAULT_OPTS '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"'
|
||||
end
|
||||
|
||||
fzf $argv
|
||||
end
|
9
.config/fish/functions/_puffer_fish_expand_bang.fish
Normal file
9
.config/fish/functions/_puffer_fish_expand_bang.fish
Normal file
|
@ -0,0 +1,9 @@
|
|||
function _puffer_fish_expand_bang
|
||||
switch (commandline -t)
|
||||
case '!'
|
||||
commandline -t $history[1]
|
||||
case '*'
|
||||
commandline -i '!'
|
||||
end
|
||||
end
|
||||
|
9
.config/fish/functions/_puffer_fish_expand_dots.fish
Normal file
9
.config/fish/functions/_puffer_fish_expand_dots.fish
Normal file
|
@ -0,0 +1,9 @@
|
|||
function _puffer_fish_expand_dots -d 'expand ... to ../.. etc'
|
||||
set -l cmd (commandline --cut-at-cursor)
|
||||
set -l split (string split -- ' ' $cmd)
|
||||
if string match --quiet --regex -- '^(\.\./)*\.\.$' $split[-1]
|
||||
commandline --insert '/..'
|
||||
else
|
||||
commandline --insert '.'
|
||||
end
|
||||
end
|
9
.config/fish/functions/_puffer_fish_expand_lastarg.fish
Normal file
9
.config/fish/functions/_puffer_fish_expand_lastarg.fish
Normal file
|
@ -0,0 +1,9 @@
|
|||
function _puffer_fish_expand_lastarg
|
||||
switch (commandline -t)
|
||||
case '!'
|
||||
commandline -t ""
|
||||
commandline -f history-token-search-backward
|
||||
case '*'
|
||||
commandline -i '$'
|
||||
end
|
||||
end
|
5
.config/fish/functions/_sponge_clear_state.fish
Normal file
5
.config/fish/functions/_sponge_clear_state.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function _sponge_clear_state
|
||||
set --erase --global _sponge_current_command
|
||||
set --erase --global _sponge_current_command_exit_code
|
||||
set --erase --global _sponge_current_command_previously_in_history
|
||||
end
|
3
.config/fish/functions/_sponge_on_exit.fish
Normal file
3
.config/fish/functions/_sponge_on_exit.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function _sponge_on_exit --on-event fish_exit
|
||||
sponge_delay=0 _sponge_remove_from_history
|
||||
end
|
24
.config/fish/functions/_sponge_on_postexec.fish
Normal file
24
.config/fish/functions/_sponge_on_postexec.fish
Normal file
|
@ -0,0 +1,24 @@
|
|||
function _sponge_on_postexec --on-event fish_postexec
|
||||
set --global _sponge_current_command_exit_code $status
|
||||
|
||||
# Remove command from the queue if it's been added previously
|
||||
if set --local index (contains --index -- $_sponge_current_command $_sponge_queue)
|
||||
set --erase _sponge_queue[$index]
|
||||
end
|
||||
|
||||
# Ignore empty commands
|
||||
if test -n $_sponge_current_command
|
||||
set --local command ''
|
||||
# Run filters
|
||||
for filter in $sponge_filters
|
||||
if $filter \
|
||||
$_sponge_current_command \
|
||||
$_sponge_current_command_exit_code \
|
||||
$_sponge_current_command_previously_in_history
|
||||
set command $_sponge_current_command
|
||||
break
|
||||
end
|
||||
end
|
||||
set --prepend --global _sponge_queue $command
|
||||
end
|
||||
end
|
16
.config/fish/functions/_sponge_on_preexec.fish
Normal file
16
.config/fish/functions/_sponge_on_preexec.fish
Normal file
|
@ -0,0 +1,16 @@
|
|||
function _sponge_on_preexec --on-event fish_preexec \
|
||||
--argument-names command
|
||||
_sponge_clear_state
|
||||
|
||||
set --global _sponge_current_command $command
|
||||
|
||||
builtin history search --case-sensitive --exact --max=1 --null $command \
|
||||
| read --local --null found_entries
|
||||
|
||||
# If a command is in the history and in the queue, ignore it, like if it wasn’t in the history
|
||||
if test (count $found_entries) -ne 0; and not contains $command $_sponge_queue
|
||||
set --global _sponge_current_command_previously_in_history true
|
||||
else
|
||||
set --global _sponge_current_command_previously_in_history false
|
||||
end
|
||||
end
|
5
.config/fish/functions/_sponge_on_prompt.fish
Normal file
5
.config/fish/functions/_sponge_on_prompt.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function _sponge_on_prompt --on-event fish_prompt
|
||||
if test $sponge_purge_only_on_exit = false
|
||||
_sponge_remove_from_history
|
||||
end
|
||||
end
|
9
.config/fish/functions/_sponge_remove_from_history.fish
Normal file
9
.config/fish/functions/_sponge_remove_from_history.fish
Normal file
|
@ -0,0 +1,9 @@
|
|||
function _sponge_remove_from_history
|
||||
|
||||
while test (count $_sponge_queue) -gt $sponge_delay
|
||||
builtin history delete --case-sensitive --exact -- $_sponge_queue[-1]
|
||||
set --erase _sponge_queue[-1]
|
||||
end
|
||||
|
||||
builtin history save
|
||||
end
|
46
.config/fish/functions/fzf_configure_bindings.fish
Normal file
46
.config/fish/functions/fzf_configure_bindings.fish
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Always installs bindings for insert and default mode for simplicity and b/c it has almost no side-effect
|
||||
# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1
|
||||
function fzf_configure_bindings --description "Installs the default key bindings for fzf.fish with user overrides passed as options."
|
||||
# no need to install bindings if not in interactive mode or running tests
|
||||
status is-interactive || test "$CI" = true; or return
|
||||
|
||||
set -f options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'processes=?' 'variables=?'
|
||||
argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null
|
||||
if test $status -ne 0
|
||||
echo "Invalid option or a positional argument was provided." >&2
|
||||
_fzf_configure_bindings_help
|
||||
return 22
|
||||
else if set --query _flag_help
|
||||
_fzf_configure_bindings_help
|
||||
return
|
||||
else
|
||||
# Initialize with default key sequences and then override or disable them based on flags
|
||||
# index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = processes, 6 = variables
|
||||
set -f key_sequences \e\cf \e\cl \e\cs \cr \e\cp \cv # \c = control, \e = escape
|
||||
set --query _flag_directory && set key_sequences[1] "$_flag_directory"
|
||||
set --query _flag_git_log && set key_sequences[2] "$_flag_git_log"
|
||||
set --query _flag_git_status && set key_sequences[3] "$_flag_git_status"
|
||||
set --query _flag_history && set key_sequences[4] "$_flag_history"
|
||||
set --query _flag_processes && set key_sequences[5] "$_flag_processes"
|
||||
set --query _flag_variables && set key_sequences[6] "$_flag_variables"
|
||||
|
||||
# If fzf bindings already exists, uninstall it first for a clean slate
|
||||
if functions --query _fzf_uninstall_bindings
|
||||
_fzf_uninstall_bindings
|
||||
end
|
||||
|
||||
for mode in default insert
|
||||
test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_directory
|
||||
test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_git_log
|
||||
test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status
|
||||
test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history
|
||||
test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] _fzf_search_processes
|
||||
test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] "$_fzf_search_vars_command"
|
||||
end
|
||||
|
||||
function _fzf_uninstall_bindings --inherit-variable key_sequences
|
||||
bind --erase -- $key_sequences
|
||||
bind --erase --mode insert -- $key_sequences
|
||||
end
|
||||
end
|
||||
end
|
3
.config/fish/functions/projectdo_build.fish
Normal file
3
.config/fish/functions/projectdo_build.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function projectdo_build
|
||||
projectdo -d build
|
||||
end
|
3
.config/fish/functions/projectdo_run.fish
Normal file
3
.config/fish/functions/projectdo_run.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function projectdo_run
|
||||
projectdo -d run
|
||||
end
|
3
.config/fish/functions/projectdo_test.fish
Normal file
3
.config/fish/functions/projectdo_test.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function projectdo_test
|
||||
projectdo -d test
|
||||
end
|
3
.config/fish/functions/projectdo_tool.fish
Normal file
3
.config/fish/functions/projectdo_tool.fish
Normal file
|
@ -0,0 +1,3 @@
|
|||
function projectdo_tool
|
||||
projectdo -d tool
|
||||
end
|
48
.config/fish/functions/replay.fish
Normal file
48
.config/fish/functions/replay.fish
Normal file
|
@ -0,0 +1,48 @@
|
|||
function replay --description "Run Bash commands replaying changes in Fish"
|
||||
switch "$argv"
|
||||
case -v --version
|
||||
echo "replay, version 1.2.1"
|
||||
case "" -h --help
|
||||
echo "Usage: replay <commands> Run Bash commands replaying changes in Fish"
|
||||
echo "Options:"
|
||||
echo " -v or --version Print version"
|
||||
echo " -h or --help Print this help message"
|
||||
case \*
|
||||
set --local env
|
||||
set --local sep @$fish_pid(random)(command date +%s)
|
||||
set --local argv $argv[1] (string escape -- $argv[2..-1])
|
||||
set --local out (command bash -c "
|
||||
$argv
|
||||
status=\$?
|
||||
[ \$status -gt 0 ] && exit \$status
|
||||
|
||||
command compgen -e | command awk -v sep=$sep '{
|
||||
gsub(/\n/, \"\\\n\", ENVIRON[\$0])
|
||||
print \$0 sep ENVIRON[\$0]
|
||||
}' && alias
|
||||
") || return
|
||||
|
||||
string replace --all -- \\n \n (
|
||||
for line in $out
|
||||
if string split -- $sep $line | read --local --line name value
|
||||
set --append env $name
|
||||
|
||||
contains -- $name SHLVL PS1 BASH_FUNC || test "$$name" = "$value" && continue
|
||||
|
||||
if test "$name" = PATH
|
||||
echo set PATH (string split -- : $value | string replace --regex --all -- '(^.*$)' '"$1"')
|
||||
else if test "$name" = PWD
|
||||
echo builtin cd "\"$value\""
|
||||
else
|
||||
echo "set --global --export $name "(string escape -- $value)
|
||||
end
|
||||
else
|
||||
set --query env[1] && string match --entire --regex -- "^alias" $line || echo "echo \"$line\""
|
||||
end
|
||||
end | string replace --all -- \$ \\\$
|
||||
for name in (set --export --names)
|
||||
contains -- $name $env || echo "set --erase $name"
|
||||
end
|
||||
) | source
|
||||
end
|
||||
end
|
33
.config/fish/functions/spark.fish
Normal file
33
.config/fish/functions/spark.fish
Normal file
|
@ -0,0 +1,33 @@
|
|||
function spark --description Sparklines
|
||||
argparse --ignore-unknown --name=spark v/version h/help m/min= M/max= -- $argv || return
|
||||
|
||||
if set --query _flag_version[1]
|
||||
echo "spark, version 1.1.0"
|
||||
else if set --query _flag_help[1]
|
||||
echo "Usage: spark <numbers ...>"
|
||||
echo " stdin | spark"
|
||||
echo "Options:"
|
||||
echo " --min=<number> Minimum range"
|
||||
echo " --max=<number> Maximum range"
|
||||
echo " -v or --version Print version"
|
||||
echo " -h or --help Print this help message"
|
||||
echo "Examples:"
|
||||
echo " spark 1 1 2 5 14 42"
|
||||
echo " seq 64 | sort --random-sort | spark"
|
||||
else if set --query argv[1]
|
||||
printf "%s\n" $argv | spark --min="$_flag_min" --max="$_flag_max"
|
||||
else
|
||||
command awk -v min="$_flag_min" -v max="$_flag_max" '
|
||||
{
|
||||
m = min == "" ? m == "" ? $0 : m > $0 ? $0 : m : min
|
||||
M = max == "" ? M == "" ? $0 : M < $0 ? $0 : M : max
|
||||
nums[NR] = $0
|
||||
}
|
||||
END {
|
||||
n = split("▁ ▂ ▃ ▄ ▅ ▆ ▇ █", sparks, " ") - 1
|
||||
while (++i <= NR)
|
||||
printf("%s", sparks[(M == m) ? 3 : sprintf("%.f", (1 + (nums[i] - m) * n / (M - m)))])
|
||||
}
|
||||
' && echo
|
||||
end
|
||||
end
|
11
.config/fish/functions/sponge_filter_failed.fish
Normal file
11
.config/fish/functions/sponge_filter_failed.fish
Normal file
|
@ -0,0 +1,11 @@
|
|||
function sponge_filter_failed \
|
||||
--argument-names command exit_code previously_in_history
|
||||
|
||||
if test $previously_in_history = true -a $sponge_allow_previously_successful = true
|
||||
return 1
|
||||
end
|
||||
|
||||
if contains $exit_code $sponge_successful_exit_codes
|
||||
return 1
|
||||
end
|
||||
end
|
11
.config/fish/functions/sponge_filter_matched.fish
Normal file
11
.config/fish/functions/sponge_filter_matched.fish
Normal file
|
@ -0,0 +1,11 @@
|
|||
function sponge_filter_matched \
|
||||
--argument-names command
|
||||
|
||||
for pattern in $sponge_regex_patterns
|
||||
if string match --regex --quiet $pattern -- $command
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return 1
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue