diff --git a/fish/.gitignore b/fish/.gitignore index 3ceea9b..e2b8233 100644 --- a/fish/.gitignore +++ b/fish/.gitignore @@ -1,5 +1,5 @@ fish_variables fisher/ -fish_user_key_bindings.fish -fzf_key_bindings.fish -private/ +functions/br.fish +functions/fish_user_key_bindings.fish +functions/fzf_key_bindings.fish diff --git a/fish/config.fish b/fish/config.fish index 21f2750..8afe1e4 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -10,21 +10,10 @@ set -gx LANG en_US.UTF-8 set -gx SBT_OPTS '-Dsbt.supershell=false' 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 set -gx JAVA_HOME (/usr/libexec/java_home -v 1.8) end -# Path -if not set -q fish_user_paths - set -U fish_user_paths ~/bin ~/go/bin -end - # FZF (https://github.com/junegunn/fzf) set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse --multi" set -gx FZF_DEFAULT_COMMAND "fd --type=file" @@ -66,7 +55,7 @@ for file in $fisher_path/conf.d/*.fish end if not functions -q fisher 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..." fish -c fisher end diff --git a/fish/functions/fbrew.fish b/fish/functions/fbrew.fish index b81a204..9ce47b6 100644 --- a/fish/functions/fbrew.fish +++ b/fish/functions/fbrew.fish @@ -1,4 +1,104 @@ 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 echo "Usage: fbrew " return 1 @@ -12,97 +112,7 @@ function fbrew --description "Fuzzy homebrew" case '*' echo "Unsupported command: $argv[1]" end -end - -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 -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 + + functions --erase _fbrew_install + functions --erase _fbrew_uninstall end diff --git a/fish/functions/fish_colors.fish b/fish/functions/fish_colors.fish index 4f18e13..7cc37bb 100644 --- a/fish/functions/fish_colors.fish +++ b/fish/functions/fish_colors.fish @@ -1,14 +1,41 @@ 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*') - if test $plain -eq 1 - echo $i $$i - else - echo $i (set_color $$i)$$i(set_color normal) + # Helper function that prints the fish commands needed to set the current colors + function _fish_colors_commands --argument-names _variable_scope + set -l color_list (set -n | grep fish | grep color | grep -v __) + for i in $color_list + echo (string join ' ' -- set $_variable_scope $i $$i) 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 diff --git a/fish/functions/fish_trace.fish b/fish/functions/fish_trace.fish deleted file mode 100644 index 9b85083..0000000 --- a/fish/functions/fish_trace.fish +++ /dev/null @@ -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 diff --git a/fish/functions/fish_vars.fish b/fish/functions/fish_vars.fish new file mode 100644 index 0000000..20e10e7 --- /dev/null +++ b/fish/functions/fish_vars.fish @@ -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 "" + end + end + + printf $_table_format (printf "%.s_" (seq 24)) (printf "%.s_" (seq 38)) + +end diff --git a/install-fzf.sh b/install-fzf.sh new file mode 100755 index 0000000..ff22eb1 --- /dev/null +++ b/install-fzf.sh @@ -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 diff --git a/install.sh b/install.sh index 51cb25c..f4723f3 100755 --- a/install.sh +++ b/install.sh @@ -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" if [ ! -f "$VIM_PLUG_DST" ]; then 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 # 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 sudo chsh -s "$BREW_PREFIX/bin/fish" `whoami` +# Install fzf keybindings +"$DOTFILES/install-fzf.sh" + # Install symlinks "$DOTFILES/install-symlinks.sh"