Fish config refactor

Move things into sub-files and sub-directories
Add ensure_path function to make sure stuff doesn't get spammed multiple
times into the PATH
This commit is contained in:
Tim McCarthy
2020-03-31 12:42:50 -07:00
parent a8e6dd2c75
commit 3ccf865b99
12 changed files with 51 additions and 49 deletions

7
fish/apps/autojump.fish Normal file
View File

@@ -0,0 +1,7 @@
# ========
# Autojump
# https://github.com/wting/autojump
# ========
[ -f /usr/local/share/autojump/autojump.fish ]; and . /usr/local/share/autojump/autojump.fish
[ -f /usr/share/autojump/autojump.fish ]; and . /usr/share/autojump/autojump.fish

101
fish/apps/iterm2.fish Normal file
View File

@@ -0,0 +1,101 @@
if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ "$TERM" != screen ]; end
function iterm2_status
printf "\033]133;D;%s\007" $argv
end
# Mark start of prompt
function iterm2_prompt_mark
printf "\033]133;A\007"
end
# Mark end of prompt
function iterm2_prompt_end
printf "\033]133;B\007"
end
# Tell terminal to create a mark at this location
function iterm2_preexec
# For other shells we would output status here but we can't do that in fish.
printf "\033]133;C;\007"
end
# Usage: iterm2_set_user_var key value
# These variables show up in badges (and later in other places). For example
# iterm2_set_user_var currentDirectory "$PWD"
# Gives a variable accessible in a badge by \(user.currentDirectory)
# Calls to this go in iterm2_print_user_vars.
function iterm2_set_user_var
printf "\033]1337;SetUserVar=%s=%s\007" "$argv[1]" (printf "%s" "$argv[2]" | base64 | tr -d "\n")
end
# iTerm2 inform terminal that command starts here
function iterm2_precmd
printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=$PWD\007" $USER $iterm2_hostname
# Users can define a function called iterm2_print_user_vars.
# It should call iterm2_set_user_var and produce no other output.
if functions -q -- iterm2_print_user_vars
iterm2_print_user_vars
end
end
functions -c fish_prompt iterm2_fish_prompt
if functions -q -- fish_mode_prompt
# This path for fish 2.2. Works nicer with fish_vi_mode.
functions -c fish_mode_prompt iterm2_fish_mode_prompt
function fish_mode_prompt --description 'Write out the mode prompt; do not replace this. Instead, change fish_mode_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_mode_prompt instead.'
set -l last_status $status
iterm2_status $last_status
if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null
iterm2_prompt_mark
end
sh -c "exit $last_status"
iterm2_fish_mode_prompt
end
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, change fish_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_prompt instead.'
# Remove the trailing newline from the original prompt. This is done
# using the string builtin from fish, but to make sure any escape codes
# are correctly interpreted, use %b for printf.
printf "%b" (string join "\n" (iterm2_fish_prompt))
iterm2_prompt_end
end
else
# Pre-2.2 path
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, change fish_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_prompt instead.'
# Save our status
set -l last_status $status
iterm2_status $last_status
if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null
iterm2_prompt_mark
end
# Restore the status
sh -c "exit $last_status"
iterm2_fish_prompt
iterm2_prompt_end
end
end
function underscore_change -v _
if [ x$_ = xfish ]
iterm2_precmd
else
iterm2_preexec
end
end
# If hostname -f is slow for you, set iterm2_hostname before sourcing this script
if not set -q iterm2_hostname
set iterm2_hostname (hostname -f)
end
iterm2_precmd
printf "\033]1337;ShellIntegrationVersion=5;shell=fish\007"
end

35
fish/apps/rvm.fish Normal file
View File

@@ -0,0 +1,35 @@
function rvm --description='Ruby enVironment Manager'
# run RVM and capture the resulting environment
set --local env_file (mktemp -t rvm.fish.XXXXXXXXXX)
bash -c 'source ~/.rvm/scripts/rvm; rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# apply rvm_* and *PATH variables from the captured environment
and eval (grep '^rvm\|^[^=]*PATH\|^GEM_HOME' $env_file | grep -v '_clr=' | sed '/^[^=]*PATH/y/:/ /; s/^/set -xg /; s/=/ /; s/$/ ;/; s/(//; s/)//')
# clean up
rm -f $env_file
end
function __handle_rvmrc_stuff --on-variable PWD
# Source a .rvmrc file in a directory after changing to it, if it exists.
# To disable this fature, set rvm_project_rvmrc=0 in $HOME/.rvmrc
if test "$rvm_project_rvmrc" != 0
set -l cwd $PWD
while true
if contains $cwd "" $HOME "/"
if test "$rvm_project_rvmrc_default" = 1
rvm default 1>/dev/null 2>&1
end
break
else
if begin; test -s ".rvmrc"; or test -s ".ruby-version"; or test -s ".ruby-gemset"; end
eval "rvm reload" > /dev/null
break
else
set cwd (dirname "$cwd")
end
end
end
set -e cwd
end
end