fish: add fish_vars, improve fish_colors

This commit is contained in:
Charles Gould 2020-04-09 02:14:45 -05:00
parent 737cbd0d9a
commit 87fdffca9e
8 changed files with 183 additions and 127 deletions

6
fish/.gitignore vendored
View File

@ -1,5 +1,5 @@
fish_variables fish_variables
fisher/ fisher/
fish_user_key_bindings.fish functions/br.fish
fzf_key_bindings.fish functions/fish_user_key_bindings.fish
private/ functions/fzf_key_bindings.fish

View File

@ -10,21 +10,10 @@ set -gx LANG en_US.UTF-8
set -gx SBT_OPTS '-Dsbt.supershell=false' set -gx SBT_OPTS '-Dsbt.supershell=false'
set -gx ENHANCD_DISABLE_DOT 1 set -gx ENHANCD_DISABLE_DOT 1
if command -q moar
set -gx PAGER moar
else if command -q most
set -gx PAGER most
end
if test -x /usr/libexec/java_home if test -x /usr/libexec/java_home
set -gx JAVA_HOME (/usr/libexec/java_home -v 1.8) set -gx JAVA_HOME (/usr/libexec/java_home -v 1.8)
end end
# Path
if not set -q fish_user_paths
set -U fish_user_paths ~/bin ~/go/bin
end
# FZF (https://github.com/junegunn/fzf) # FZF (https://github.com/junegunn/fzf)
set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse --multi" set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse --multi"
set -gx FZF_DEFAULT_COMMAND "fd --type=file" set -gx FZF_DEFAULT_COMMAND "fd --type=file"
@ -66,7 +55,7 @@ for file in $fisher_path/conf.d/*.fish
end end
if not functions -q fisher if not functions -q fisher
echo "Installing fish-shell package manager: $fisher_path/functions/fisher.fish" echo "Installing fish-shell package manager: $fisher_path/functions/fisher.fish"
curl https://git.io/fisher --create-dirs -sLo $fisher_path/functions/fisher.fish curl -fsSL -o $fisher_path/functions/fisher.fish --create-dirs https://git.io/fisher
echo "Installing fish-shell packages..." echo "Installing fish-shell packages..."
fish -c fisher fish -c fisher
end end

View File

@ -1,4 +1,104 @@
function fbrew --description "Fuzzy homebrew" function fbrew --description "Fuzzy homebrew"
# Helper function for 'brew install'
function _fbrew_install
set --local inst_pkgs $argv
if test (count $inst_pkgs) -eq 0
set inst_pkgs (brew search | eval "fzf --prompt='[brew:install] '")
end
if test (count $inst_pkgs) -gt 0
echo "Installing: $inst_pkgs"
brew install $inst_pkgs
end
functions --erase _fbrew_install
end
# Helper function for 'brew uninstall'
function _fbrew_uninstall
set --local uninst_pkgs $argv
# Don't uninstall these packages
set --local locked_pkgs node python
if test (count $uninst_pkgs) -eq 0
set uninst_pkgs (brew leaves | eval "fzf --prompt='[brew:uninstall] '")
end
if test (count $uninst_pkgs) -gt 0
echo "Determining package dependencies..."
# Output is multiline with format "pkgname:" if no dependencies, otherwise "pkgname: dep1 dep2 dep3 ..."
set --local brew_deps_installed (string collect (brew deps --installed))
# Accumulate packages and their dependencies
set --local uninst_pkgs_all $uninst_pkgs
set --local locked_pkgs_all $locked_pkgs
for bdi in $brew_deps_installed
set --local pkg (string split ':' $bdi | head -n 1)
set --local deps (string split ' ' (string split ':' $bdi | tail -n +2))
if contains -- $pkg $uninst_pkgs
for dep in $deps
if test -n $dep
if not contains -- $dep $uninst_pkgs_all
set uninst_pkgs_all $uninst_pkgs_all $dep
end
end
end
end
if contains -- $pkg $locked_pkgs
for dep in $deps
if test -n $dep
if not contains -- $dep $locked_pkgs_all
set locked_pkgs_all $locked_pkgs_all $dep
end
end
end
end
end
# Don't uninstall dependencies of other installed packages
set --local uninst_pkgs_final $uninst_pkgs_all
for bdi in $brew_deps_installed
set --local pkg (string split ':' $bdi | head -n 1)
set --local deps (string split ' ' (string split ':' $bdi | tail -n +2))
if not contains -- $pkg $uninst_pkgs_all
for dep in $deps
if test -n $dep
if set --local index (contains --index -- $dep $uninst_pkgs_final)
set --erase uninst_pkgs_final[$index]
end
end
end
end
end
# Don't uninstall dependencies of locked packages
set --local uninst_pkgs_leave
for pkg in $locked_pkgs_all
if test -n $pkg
if set --local index (contains --index -- $pkg $uninst_pkgs_final)
set uninst_pkgs_leave $uninst_pkgs_leave $pkg
set --erase uninst_pkgs_final[$index]
end
end
end
if test (count $uninst_pkgs_final) -gt 0
echo "Uninstalling: $uninst_pkgs_final"
brew uninstall $uninst_pkgs_final
end
if test (count $uninst_pkgs_leave) -gt 0
echo "Will not uninstall: $uninst_pkgs_leave"
end
end
functions --erase _fbrew_uninstall
end
if test (count $argv) -eq 0 if test (count $argv) -eq 0
echo "Usage: fbrew <install|uninstall>" echo "Usage: fbrew <install|uninstall>"
return 1 return 1
@ -12,97 +112,7 @@ function fbrew --description "Fuzzy homebrew"
case '*' case '*'
echo "Unsupported command: $argv[1]" echo "Unsupported command: $argv[1]"
end end
end
functions --erase _fbrew_install
function _fbrew_install functions --erase _fbrew_uninstall
set --local inst_pkgs $argv
if test (count $inst_pkgs) -eq 0
set inst_pkgs (brew search | eval "fzf --prompt='[brew:install] '")
end
if test (count $inst_pkgs) -gt 0
echo "Installing: $inst_pkgs"
brew install $inst_pkgs
end
end
function _fbrew_uninstall
set --local uninst_pkgs $argv
# Don't uninstall these packages
set --local locked_pkgs node python
if test (count $uninst_pkgs) -eq 0
set uninst_pkgs (brew leaves | eval "fzf --prompt='[brew:uninstall] '")
end
if test (count $uninst_pkgs) -gt 0
echo "Determining package dependencies..."
# Output is multiline with format "pkgname:" if no dependencies, otherwise "pkgname: dep1 dep2 dep3 ..."
set --local brew_deps_installed (string collect (brew deps --installed))
# Accumulate packages and their dependencies
set --local uninst_pkgs_all $uninst_pkgs
set --local locked_pkgs_all $locked_pkgs
for bdi in $brew_deps_installed
set --local pkg (string split ':' $bdi | head -n 1)
set --local deps (string split ' ' (string split ':' $bdi | tail -n +2))
if contains -- $pkg $uninst_pkgs
for dep in $deps
if test -n $dep
if not contains -- $dep $uninst_pkgs_all
set uninst_pkgs_all $uninst_pkgs_all $dep
end
end
end
end
if contains -- $pkg $locked_pkgs
for dep in $deps
if test -n $dep
if not contains -- $dep $locked_pkgs_all
set locked_pkgs_all $locked_pkgs_all $dep
end
end
end
end
end
# Don't uninstall dependencies of other installed packages
set --local uninst_pkgs_final $uninst_pkgs_all
for bdi in $brew_deps_installed
set --local pkg (string split ':' $bdi | head -n 1)
set --local deps (string split ' ' (string split ':' $bdi | tail -n +2))
if not contains -- $pkg $uninst_pkgs_all
for dep in $deps
if test -n $dep
if set --local index (contains --index -- $dep $uninst_pkgs_final)
set --erase uninst_pkgs_final[$index]
end
end
end
end
end
# Don't uninstall dependencies of locked packages
set --local uninst_pkgs_leave
for pkg in $locked_pkgs_all
if test -n $pkg
if set --local index (contains --index -- $pkg $uninst_pkgs_final)
set uninst_pkgs_leave $uninst_pkgs_leave $pkg
set --erase uninst_pkgs_final[$index]
end
end
end
if test (count $uninst_pkgs_final) -gt 0
echo "Uninstalling: $uninst_pkgs_final"
brew uninstall $uninst_pkgs_final
end
if test (count $uninst_pkgs_leave) -gt 0
echo "Will not uninstall: $uninst_pkgs_leave"
end
end
end end

View File

@ -1,14 +1,41 @@
function fish_colors --description 'Print the fish color variables' function fish_colors --description 'Print the fish color variables'
set --local plain 0
if contains -- '--plain' $argv
set plain 1
end
for i in (set -n | string match 'fish*_color*') # Helper function that prints the fish commands needed to set the current colors
if test $plain -eq 1 function _fish_colors_commands --argument-names _variable_scope
echo $i $$i set -l color_list (set -n | grep fish | grep color | grep -v __)
else for i in $color_list
echo $i (set_color $$i)$$i(set_color normal) echo (string join ' ' -- set $_variable_scope $i $$i)
end end
end end
# Helper function that prints examples using the current colors
function _fish_colors_examples
set -l color_list (set -n | grep fish | grep color | grep -v __)
set -l normal (set_color normal)
set -l bold (set_color --bold)
printf "\n| %-32s | %-38s | %-22s |\n" Variable Definition Example
echo '|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|'
for variable in $color_list
set -l value $$variable
set -l color (set_color $value ^/dev/null)
or begin
printf "| %-32s | %s%-38s | %-22s |\n" "$variable" (set_color --bold white --background=red) "$value" "The quick brown fox..."
continue
end
printf "| $normal%-32s | $bold%-38s$normal | $color%-22s$normal |\n" "$variable" "$value" "The quick brown fox..."
end
echo '|__________________________________|________________________________________|________________________|'\n
end
if contains -- '-g' $argv; or contains -- '--global' $argv
_fish_colors_commands '--global'
else if contains -- '-U' $argv; or contains -- '--universal' $argv
_fish_colors_commands '--universal'
else
_fish_colors_examples
end
functions --erase _fish_colors_commands
functions --erase _fish_colors_examples
end end

View File

@ -1,9 +0,0 @@
function fish_trace --description 'Toggle fish function tracing'
if not set --query fish_trace
echo 'Enabling fish function tracing...'
set --global fish_trace 1
else
echo 'Disabling fish function tracing...'
set --erase fish_trace
end
end

View File

@ -0,0 +1,28 @@
function fish_vars
set -l _special_variables BROWSER CDPATH LANG PATH SHLVL fish_ambiguous_width fish_emoji_width fish_escape_delay_ms fish_trace fish_user_paths hostname umask version
set -l _path_variables CDPATH PATH fish_user_paths
set -l _table_format "| %-24s | %-38s |\n"
printf "\n$_table_format" Variable Value
printf $_table_format (printf "%.s¯" (seq 24)) (printf "%.s¯" (seq 38))
for variable in $_special_variables
if set -q $variable
if contains -- $variable $_path_variables
set -l paths (string collect (string split " " $$variable))
printf $_table_format $variable "- $paths[1]"
for path in $paths[2..-1]
printf $_table_format "" "- $path"
end
else
printf $_table_format $variable $$variable
end
else
printf $_table_format $variable "<unset>"
end
end
printf $_table_format (printf "%.s_" (seq 24)) (printf "%.s_" (seq 38))
end

8
install-fzf.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# Install fzf key-bindings
FZF_INSTALLER=$(brew --prefix)/opt/fzf/install
if [ -x "$FZF_INSTALLER" ]; then
"$FZF_INSTALLER" --key-bindings --no-completion --no-update-rc --no-bash --no-zsh
end

View File

@ -7,7 +7,7 @@ VIM_PLUG_SRC="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vi
VIM_PLUG_DST="$HOME/.local/share/nvim/site/autoload/plug.vim" VIM_PLUG_DST="$HOME/.local/share/nvim/site/autoload/plug.vim"
if [ ! -f "$VIM_PLUG_DST" ]; then if [ ! -f "$VIM_PLUG_DST" ]; then
echo "Downloading plug.vim ..." echo "Downloading plug.vim ..."
curl -fLo "$VIM_PLUG_DST" --create-dirs "$VIM_PLUG_SRC" curl -fsSL -o "$VIM_PLUG_DST" --create-dirs "$VIM_PLUG_SRC"
fi fi
# Add Homebrew-managed shells to system list # Add Homebrew-managed shells to system list
@ -18,5 +18,8 @@ grep -q "$BREW_PREFIX/bin/fish" /etc/shells || echo "$BREW_PREFIX/bin/fish" | su
# Make fish the default shell # Make fish the default shell
sudo chsh -s "$BREW_PREFIX/bin/fish" `whoami` sudo chsh -s "$BREW_PREFIX/bin/fish" `whoami`
# Install fzf keybindings
"$DOTFILES/install-fzf.sh"
# Install symlinks # Install symlinks
"$DOTFILES/install-symlinks.sh" "$DOTFILES/install-symlinks.sh"