1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2025-11-28 07:06:37 +00:00

Fish: Move fisher to separate directory

This commit is contained in:
Phantop 2019-04-04 16:50:36 -04:00
parent 6434991691
commit d6df39be92
41 changed files with 699 additions and 6 deletions

View file

@ -2,17 +2,23 @@
if test (hostname) = aperture
set -Ux D /mnt/LocalDiskD
end
set -gx ANDROID_HOME $D/Installs/Android/sdk
set -gx fish_user_paths $D/Tools ~/.local/bin /usr/bin /usr/local/bin /bin /usr/sbin /usr/local/sbin /sbin $PLAN9/bin $ANDROID_HOME/platform-tools
set -gx ENV .profile
set -gx FFF_CD_FILE ~/.fff_d
set -g fisher_path ~/.config/fish/fisher
set fish_function_path $fish_function_path[1] $fisher_path/functions $fish_function_path[2..-1]
set fish_complete_path $fish_complete_path[1] $fisher_path/completions $fish_complete_path[2..-1]
for file in $fisher_path/conf.d/*.fish
builtin source $file 2> /dev/null
end
# PROGRAM SETTINGS #
set -gx EDITOR nvim
set -gx PAGER "nvim -c 'set ft=man' -"
# AUTOJUMP #
alias j=z
set -U Z_CMD "j"
# LOAD XRESOURCES #
xrdb ~/.Xresources

View file

@ -1,8 +1,8 @@
# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR --export D:/mnt/LocalDiskD
SETUVAR ZO_CMD:zo
SETUVAR Z_CMD:z
SETUVAR ZO_CMD:jo
SETUVAR Z_CMD:j
SETUVAR Z_DATA:/home/glados/\x2elocal/share/z/data
SETUVAR Z_DATA_DIR:/home/glados/\x2elocal/share/z
SETUVAR Z_EXCLUDE:/home/glados

View file

@ -0,0 +1 @@
fisher complete

View file

@ -0,0 +1,8 @@
# Deactivate the default virtualenv prompt so that we can add our own
set --global --export VIRTUAL_ENV_DISABLE_PROMPT 1
# Whether or not is a fresh session
set --global _pure_fresh_session true
# Register `_pure_prompt_new_line` as an event handler fot `fish_prompt`
functions -q _pure_prompt_new_line

View file

@ -0,0 +1,65 @@
set --universal pure_version 2.1.4 # used for bug report
# Base colors
_pure_set_default pure_color_primary (set_color blue)
_pure_set_default pure_color_info (set_color cyan)
_pure_set_default pure_color_mute (set_color brblack)
_pure_set_default pure_color_success (set_color magenta)
_pure_set_default pure_color_normal (set_color normal)
_pure_set_default pure_color_danger (set_color red)
_pure_set_default pure_color_light (set_color white)
_pure_set_default pure_color_warning (set_color yellow)
_pure_set_default pure_color_dark (set_color black)
# Prompt
_pure_set_default pure_symbol_prompt ""
_pure_set_default pure_symbol_reverse_prompt "" # used for VI mode
_pure_set_default pure_color_prompt_on_error $pure_color_danger
_pure_set_default pure_color_prompt_on_success $pure_color_success
# Current Working Directory
_pure_set_default pure_color_current_directory $pure_color_primary
# Git
_pure_set_default pure_symbol_git_unpulled_commits "⇣"
_pure_set_default pure_symbol_git_unpushed_commits "⇡"
_pure_set_default pure_symbol_git_dirty "*"
_pure_set_default pure_color_git_unpulled_commits $pure_color_info
_pure_set_default pure_color_git_unpushed_commits $pure_color_info
_pure_set_default pure_color_git_branch $pure_color_mute
_pure_set_default pure_color_git_dirty $pure_color_mute
# SSH info
_pure_set_default pure_color_ssh_hostname $pure_color_mute
_pure_set_default pure_color_ssh_separator $pure_color_mute
_pure_set_default pure_color_ssh_user_normal $pure_color_mute
_pure_set_default pure_color_ssh_user_root $pure_color_light
# Virtualenv for Pyhon
_pure_set_default pure_color_virtualenv $pure_color_mute
# Print current working directory at the beginning of prompt
# true (default): current directory, git, user@hostname (ssh-only), command duration
# false: user@hostname (ssh-only), current directory, git, command duration
_pure_set_default pure_begin_prompt_with_current_directory true
# Show exit code of last command as a separate prompt character (cf. https://github.com/sindresorhus/pure/wiki#show-exit-code-of-last-command-as-a-separate-prompt-character)
# false - single prompt character, default
# true - separate prompt character
_pure_set_default pure_separate_prompt_on_error false
# Max execution time of a process before its run time is shown when it exits
_pure_set_default pure_threshold_command_duration 5
_pure_set_default pure_color_command_duration $pure_color_warning
# Right Prompt variables
_pure_set_default pure_right_prompt ""
_pure_set_default pure_color_right_prompt $pure_color_normal
# VI mode indicator
# true (default): indicate a non-insert mode by reversing the prompt symbol ()
# false: indicate vi mode with [I], [N], [V]
_pure_set_default pure_reverse_prompt_symbol_in_vimode true
# Title
_pure_set_default pure_symbol_title_bar_separator "—"

View file

@ -0,0 +1,44 @@
if test -z "$Z_DATA"
if test -z "$XDG_DATA_HOME"
set -U Z_DATA_DIR "$HOME/.local/share/z"
else
set -U Z_DATA_DIR "$XDG_DATA_HOME/z"
end
set -U Z_DATA "$Z_DATA_DIR/data"
end
if test ! -e "$Z_DATA"
if test ! -e "$Z_DATA_DIR"
mkdir -p -m 700 "$Z_DATA_DIR"
end
touch "$Z_DATA"
end
if test -z "$Z_CMD"
set -U Z_CMD "z"
end
set -U ZO_CMD "$Z_CMD"o
if test ! -z $Z_CMD
function $Z_CMD -d "jump around"
__z $argv
end
end
if test ! -z $ZO_CMD
function $ZO_CMD -d "open target dir"
__z -d $argv
end
end
if not set -q Z_EXCLUDE
set -U Z_EXCLUDE $HOME
end
# Setup completions once first
__z_complete
function __z_on_variable_pwd --on-variable PWD
__z_add
end

View file

@ -1,3 +1,2 @@
rafaelrinaldi/pure
jethrokuan/z
jorgebucaran/fisher

View file

@ -0,0 +1,180 @@
function __z -d "Jump to a recent directory."
function __print_help -d "Print z help."
printf "Usage: $Z_CMD [-celrth] regex1 regex2...\n\n"
printf " -c --clean Removes directories that no longer exist from $Z_DATA\n"
printf " -d --dir Opens matching directory using system file manager.\n"
printf " -e --echo Prints best match, no cd\n"
printf " -l --list List matches and scores, no cd\n"
printf " -p --purge Delete all entries from $Z_DATA\n"
printf " -r --rank Search by rank\n"
printf " -t --recent Search by recency\n"
printf " -x --delete Removes the current directory from $Z_DATA\n"
printf " -h --help Print this help\n\n"
if type -q fisher
printf "Run `fisher help z` for more information.\n"
end
end
function __z_legacy_escape_regex
# taken from escape_string_pcre2 in fish
# used to provide compatibility with fish 2
for c in (string split '' $argv)
if contains $c (string split '' '.^$*+()?[{}\\|-]')
printf \\
end
printf '%s' $c
end
end
set -l options "h/help" "c/clean" "e/echo" "l/list" "p/purge" "r/rank" "t/recent" "d/directory" "x/delete"
argparse $options -- $argv
if set -q _flag_help
__print_help
return 0
else if set -q _flag_clean
__z_clean
printf "%s cleaned!\n" $Z_DATA
return 0
else if set -q _flag_purge
echo > $Z_DATA
printf "%s purged!\n" $Z_DATA
return 0
else if set -q _flag_delete
sed -i -e "\:^$PWD|.*:d" $Z_DATA
return 0
end
set -l typ
if set -q _flag_rank
set typ "rank"
else if set -q _flag_recent
set typ "recent"
end
set -l z_script '
function frecent(rank, time) {
dx = t-time
if( dx < 3600 ) return rank*4
if( dx < 86400 ) return rank*2
if( dx < 604800 ) return rank/2
return rank/4
}
function output(matches, best_match, common) {
# list or return the desired directory
if( list ) {
cmd = "sort -nr"
for( x in matches ) {
if( matches[x] ) {
printf "%-10s %s\n", matches[x], x | cmd
}
}
if( common ) {
printf "%-10s %s\n", "common:", common > "/dev/stderr"
}
} else {
if( common ) best_match = common
print best_match
}
}
function common(matches) {
# find the common root of a list of matches, if it exists
for( x in matches ) {
if( matches[x] && (!short || length(x) < length(short)) ) {
short = x
}
}
if( short == "/" ) return
for( x in matches ) if( matches[x] && index(x, short) != 1 ) {
return
}
return short
}
BEGIN {
hi_rank = ihi_rank = -9999999999
}
{
if( typ == "rank" ) {
rank = $2
} else if( typ == "recent" ) {
rank = $3 - t
} else rank = frecent($2, $3)
if( $1 ~ q ) {
matches[$1] = rank
} else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank
if( matches[$1] && matches[$1] > hi_rank ) {
best_match = $1
hi_rank = matches[$1]
} else if( imatches[$1] && imatches[$1] > ihi_rank ) {
ibest_match = $1
ihi_rank = imatches[$1]
}
}
END {
# prefer case sensitive
if( best_match ) {
output(matches, best_match, common(matches))
} else if( ibest_match ) {
output(imatches, ibest_match, common(imatches))
}
}
'
set -l qs
for arg in $argv
set -l escaped $arg
if string escape --style=regex '' ^/dev/null >/dev/null # use builtin escape if available
set escaped (string escape --style=regex $escaped)
else
set escaped (__z_legacy_escape_regex $escaped)
end
# Need to escape twice, see https://www.math.utah.edu/docs/info/gawk_5.html#SEC32
set escaped (string replace --all \\ \\\\ $escaped)
set qs $qs $escaped
end
set -l q (string join '.*' $qs)
if set -q _flag_list
# Handle list separately as it can print common path information to stderr
# which cannot be captured from a subcommand.
command awk -v t=(date +%s) -v list="list" -v typ="$typ" -v q="$q" -F "|" $z_script "$Z_DATA"
else
set target (command awk -v t=(date +%s) -v typ="$typ" -v q="$q" -F "|" $z_script "$Z_DATA")
if test "$status" -gt 0
return
end
if test -z "$target"
printf "'%s' did not match any results\n" "$argv"
return 1
end
if set -q _flag_list
echo "$target" | tr ";" "\n" | sort -nr
return 0
end
if set -q _flag_echo
printf "%s\n" "$target"
else if set -q _flag_directory
# Be careful, in msys2, explorer always return 1
if test "$OS" = Windows_NT
type -q explorer;and explorer "$target"; return 0;
echo "Cannot open file explorer"; return 1;
else
type -q xdg-open;and xdg-open "$target"; and return $status;
type -q open;and open "$target"; and return $status;
echo "Not sure how to open file manager"; and return 1;
end
else
pushd "$target"
end
end
end

View file

@ -0,0 +1,49 @@
function __z_add -d "Add PATH to .z file"
for i in $Z_EXCLUDE
if contains -- $PWD $i
return 0 #Path excluded
end
end
set -l tmpfile (mktemp $Z_DATA.XXXXXX)
if test -f $tmpfile
set -l path (string replace --all \\ \\\\ $PWD)
command awk -v path=$path -v now=(date +%s) -F "|" '
BEGIN {
rank[path] = 1
time[path] = now
}
$2 >= 1 {
if( $1 == path ) {
rank[$1] = $2 + 1
time[$1] = now
}
else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if( count > 1000 ) {
for( i in rank ) print i "|" 0.9*rank[i] "|" time[i] # aging
}
else for( i in rank ) print i "|" rank[i] "|" time[i]
}
' $Z_DATA 2>/dev/null >$tmpfile
if test ! -z "$Z_OWNER"
chown $Z_OWNER:(id -ng $Z_OWNER) $tmpfile
end
#
# Don't use redirection here as it can lead to a race condition where $Z_DATA is clobbered.
# Note: There is a still a possible race condition where an old version of $Z_DATA is
# read by one instance of Fish before another instance of Fish writes its copy.
#
command mv $tmpfile $Z_DATA
or command rm $tmpfile
end
__z_complete
end

View file

@ -0,0 +1,13 @@
function __z_clean -d "Clean up .z file to remove paths no longer valid"
set -l tmpfile (mktemp $Z_DATA.XXXXXX)
if test -f $tmpfile
while read line
set -l path (string split '|' $line)[1]
test -d $path; and echo $line
end < $Z_DATA > $tmpfile
command mv -f $tmpfile $Z_DATA
end
__z_complete
end

View file

@ -0,0 +1,14 @@
function __z_complete -d "add completions"
set -l __z_marks (string replace -r '\|.*' '' < $Z_DATA | string escape)
complete -c $Z_CMD -a "$__z_marks" -f
complete -c $ZO_CMD -a "$__z_marks" -f
complete -c $Z_CMD -s c -l clean -d "Cleans out $Z_DATA"
complete -c $Z_CMD -s e -l echo -d "Prints best match, no cd"
complete -c $Z_CMD -s l -l list -d "List matches, no cd"
complete -c $Z_CMD -s p -l purge -d "Purges $Z_DATA"
complete -c $Z_CMD -s r -l rank -d "Searches by rank, cd"
complete -c $Z_CMD -s t -l recent -d "Searches by recency, cd"
complete -c $Z_CMD -s h -l help -d "Print help"
end

View file

@ -0,0 +1,32 @@
set fail 1
function _pure_format_time \
--description="Format milliseconds to a human readable format" \
--argument-names milliseconds threshold
if test $milliseconds -lt 0; return $fail; end
set --local seconds (math -s0 "$milliseconds / 1000 % 60")
set --local minutes (math -s0 "$milliseconds / 60000 % 60")
set --local hours (math -s0 "$milliseconds / 3600000 % 24")
set --local days (math -s0 "$milliseconds / 86400000")
set --local time
if test $days -gt 0
set time $time (printf "%sd" $days)
end
if test $hours -gt 0
set time $time (printf "%sh" $hours)
end
if test $minutes -gt 0
set time $time (printf "%sm" $minutes)
end
if test $seconds -gt $threshold
set time $time (printf "%ss" $seconds)
end
echo -e (string join ' ' $time)
end

View file

@ -0,0 +1,14 @@
function _pure_get_prompt_symbol \
--description 'Print prompt symbol' \
--argument-names exit_code
set --local prompt_symbol $pure_symbol_prompt
set --local is_vi_mode (string match -r "fish_(vi|hybrid)_key_bindings" $fish_key_bindings)
if test -n "$is_vi_mode" \
-a "$pure_reverse_prompt_symbol_in_vimode" = true \
-a "$fish_bind_mode" != "insert"
set prompt_symbol $pure_symbol_reverse_prompt
end
echo "$prompt_symbol"
end

View file

@ -0,0 +1,14 @@
function _pure_parse_directory \
--description "Replace '$HOME' with '~'" \
--argument-names max_path_length
set --local folder (string replace $HOME '~' $PWD)
if test -n "$max_path_length";
if test (string length $folder) -gt $max_path_length;
# If path exceeds maximum symbol limit, use default fish path formating function
set folder (prompt_pwd)
end
end
echo $folder
end

View file

@ -0,0 +1,4 @@
function _pure_parse_git_branch --description "Parse current Git branch name"
command git symbolic-ref --short HEAD 2>/dev/null;
or echo (command git show-ref --head -s --abbrev HEAD)[1]
end

View file

@ -0,0 +1,11 @@
function _pure_print_prompt
set --local prompt
for prompt_part in $argv
if test (_pure_string_width $prompt_part) -gt 0
set prompt "$prompt $prompt_part"
end
end
echo (string trim -l $prompt)
end

View file

@ -0,0 +1,10 @@
function _pure_prompt \
--description 'Print prompt symbol' \
--argument-names exit_code
set --local virtualenv (_pure_prompt_virtualenv) # Python virtualenv name
set --local vimode_indicator (_pure_prompt_vimode) # vi-mode indicator
set --local pure_symbol (_pure_prompt_symbol $exit_code)
echo (_pure_print_prompt $virtualenv $vimode_indicator $pure_symbol)
end

View file

@ -0,0 +1,6 @@
function _pure_prompt_beginning
# Clear existing line content
set --local clear_line "\r\033[K"
echo $clear_line
end

View file

@ -0,0 +1,11 @@
function _pure_prompt_command_duration
set --local command_duration
# Get command execution duration
if test -n "$CMD_DURATION"
set command_duration (_pure_format_time $CMD_DURATION $pure_threshold_command_duration)
end
set --local command_duration_color "$pure_color_command_duration"
echo "$command_duration_color$command_duration"
end

View file

@ -0,0 +1,11 @@
set fail 1
function _pure_prompt_current_folder --argument-names current_prompt_width
if test -z "$current_prompt_width"; return $fail; end
set --local current_folder (_pure_parse_directory (math $COLUMNS - $current_prompt_width - 1))
set --local current_folder_color "$pure_color_current_directory"
echo "$current_folder_color$current_folder"
end

View file

@ -0,0 +1,3 @@
function _pure_prompt_ending
echo "$pure_color_normal "
end

View file

@ -0,0 +1,32 @@
function _pure_prompt_first_line \
--description 'Print contextual information before prompt.'
if not type -fq git # exit if git is not available
return 1
end
set --local prompt (_pure_print_prompt \
(_pure_prompt_ssh) \
(_pure_prompt_git) \
(_pure_prompt_command_duration)
)
set --local prompt_width (_pure_string_width $prompt)
set --local current_folder (_pure_prompt_current_folder $prompt_width)
set --local prompt_components
if test $pure_begin_prompt_with_current_directory = true
set prompt_components \
(_pure_prompt_current_folder $prompt_width) \
(_pure_prompt_git) \
(_pure_prompt_ssh) \
(_pure_prompt_command_duration)
else
set prompt_components \
(_pure_prompt_ssh) \
(_pure_prompt_current_folder $prompt_width) \
(_pure_prompt_git) \
(_pure_prompt_command_duration)
end
echo (_pure_print_prompt $prompt_components)
end

View file

@ -0,0 +1,16 @@
function _pure_prompt_git \
--description 'Print git repository informations: branch name, dirty, upstream ahead/behind'
set --local is_git_repository (command git rev-parse --is-inside-work-tree 2>/dev/null)
if test -n "$is_git_repository"
set --local git_prompt (_pure_prompt_git_branch)(_pure_prompt_git_dirty)
set --local git_pending_commits (_pure_prompt_git_pending_commits)
if test (_pure_string_width $git_pending_commits) -ne 0
set git_prompt $git_prompt $git_pending_commits
end
echo $git_prompt
end
end

View file

@ -0,0 +1,6 @@
function _pure_prompt_git_branch
set --local git_branch (_pure_parse_git_branch) # current git branch
set --local git_branch_color "$pure_color_git_branch"
echo "$git_branch_color$git_branch"
end

View file

@ -0,0 +1,12 @@
function _pure_prompt_git_dirty
set --local git_dirty_symbol
set --local git_dirty_color
set --local is_git_dirty (command git status --porcelain --ignore-submodules 2>/dev/null)
if test -n "$is_git_dirty" # untracked or un-commited files
set git_dirty_symbol "$pure_symbol_git_dirty"
set git_dirty_color "$pure_color_git_dirty"
end
echo "$git_dirty_color$git_dirty_symbol"
end

View file

@ -0,0 +1,22 @@
function _pure_prompt_git_pending_commits
set --local git_unpushed_commits
set --local git_unpulled_commits
set --local has_upstream (command git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null)
if test -n "$has_upstream" # check there is an upstream repo configured
command git rev-list --left-right --count 'HEAD...@{upstream}' \
| read --local --array git_status
set --local commit_to_push $git_status[1]
set --local commit_to_pull $git_status[2]
if test $commit_to_push -gt 0 # upstream is behind local repo
set git_unpushed_commits "$pure_color_git_unpushed_commits$pure_symbol_git_unpushed_commits"
end
if test $commit_to_pull -gt 0 # upstream is ahead of local repo
set git_unpulled_commits "$pure_color_git_unpulled_commits$pure_symbol_git_unpulled_commits"
end
end
echo "$git_unpushed_commits$git_unpulled_commits"
end

View file

@ -0,0 +1,11 @@
function _pure_prompt_new_line \
--description "Do not add a line break to a brand new session" \
--on-event fish_prompt
set --local new_line
if test $_pure_fresh_session = false
set new_line "\n"
end
echo -e -n "$new_line"
end

View file

@ -0,0 +1,5 @@
function _pure_prompt_ssh
if test "$SSH_CONNECTION" != ""
echo (_pure_prompt_ssh_user)(_pure_prompt_ssh_separator)(_pure_prompt_ssh_host)
end
end

View file

@ -0,0 +1,7 @@
function _pure_prompt_ssh_host
set --query --global hostname
or set --local hostname (hostname -s) # current host name compatible busybox
set --local hostname_color "$pure_color_ssh_hostname"
echo "$hostname_color$hostname"
end

View file

@ -0,0 +1,6 @@
function _pure_prompt_ssh_separator
set --local separator_symbol "@"
set --local separator_symbol_color "$pure_color_ssh_separator"
echo "$separator_symbol_color$separator_symbol"
end

View file

@ -0,0 +1,9 @@
function _pure_prompt_ssh_user
set --local username (whoami) # current user name
set --local username_color "$pure_color_ssh_user_normal" # default color
if test "$username" = "root"
set username_color "$pure_color_ssh_user_root" # different color for root
end
echo "$username_color$username"
end

View file

@ -0,0 +1,17 @@
function _pure_prompt_symbol \
--description 'Print prompt symbol' \
--argument-names exit_code
set --local prompt_symbol (_pure_get_prompt_symbol)
set --local command_succeed 0
set --local color_symbol $pure_color_prompt_on_success # default pure symbol color
if test $exit_code -ne $command_succeed
set color_symbol $pure_color_prompt_on_error # different pure symbol color when previous command failed
if test "$pure_separate_prompt_on_error" = true
set color_symbol "$pure_color_prompt_on_error$prompt_symbol$pure_color_prompt_on_success"
end
end
echo "$color_symbol$prompt_symbol"
end

View file

@ -0,0 +1,5 @@
function _pure_prompt_vimode
if test ! $pure_reverse_prompt_symbol_in_vimode
echo (fish_default_mode_prompt)
end
end

View file

@ -0,0 +1,8 @@
function _pure_prompt_virtualenv --description "Display virtualenv directory"
if test -n "$VIRTUAL_ENV"
set --local virtualenv (basename "$VIRTUAL_ENV")
set --local virtualenv_color "$pure_color_virtualenv"
echo "$virtualenv_color$virtualenv"
end
end

View file

@ -0,0 +1,5 @@
function _pure_set_default -S -a var default
if not set -q $var
set -g $var $default
end
end

View file

@ -0,0 +1,9 @@
function _pure_string_width \
--description 'returns raw string length, i.e. ignore ANSI-color' \
--argument-names prompt
set --local empty ''
set --local raw_prompt (string replace --all --regex '\e\[[^m]*m' $empty $prompt)
string length $raw_prompt
end

View file

@ -0,0 +1,2 @@
function fish_greeting
end

View file

@ -0,0 +1,10 @@
function fish_prompt
set --local exit_code $status # save previous exit code
echo -e -n (_pure_prompt_beginning) # init prompt context (clear current line, etc.)
echo -e (_pure_prompt_first_line) # print current path, git branch/status, command duration
echo -e -n (_pure_prompt $exit_code) # print prompt
echo -e (_pure_prompt_ending) # reset colors and end prompt
set _pure_fresh_session false
end

View file

@ -0,0 +1,16 @@
function fish_title \
--description "Set title to current folder and shell name" \
--argument-names last_command
set --local basename (string replace -r '^.*/' '' -- $PWD)
set --local current_folder (_pure_parse_directory)
set --local current_command (status current-command 2>/dev/null; or echo $_)
set --local prompt "$basename: $last_command $pure_symbol_title_bar_separator $current_command"
if test -z "$last_command"
set prompt "$current_folder $pure_symbol_title_bar_separator $current_command"
end
echo $prompt
end