From 3ccf865b99ac807950ba210e73685e56567aff31 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Tue, 31 Mar 2020 12:42:50 -0700 Subject: [PATCH] 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 --- fish/apps/autojump.fish | 7 +++ fish/{fish_startup.in => apps/iterm2.fish} | 0 fish/{ => apps}/rvm.fish | 0 fish/config.fish | 59 ++++------------------ fish/functions/ec.fish | 4 ++ fish/functions/ensure_path.fish | 7 +++ fish/functions/hybrid_bindings.fish | 6 +++ fish/functions/ip.fish | 4 ++ fish/functions/src.fish | 4 ++ fish/{ => os}/linux.fish | 0 fish/os/os.fish | 9 ++++ fish/{ => os}/osx.fish | 0 12 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 fish/apps/autojump.fish rename fish/{fish_startup.in => apps/iterm2.fish} (100%) rename fish/{ => apps}/rvm.fish (100%) create mode 100644 fish/functions/ec.fish create mode 100644 fish/functions/ensure_path.fish create mode 100644 fish/functions/hybrid_bindings.fish create mode 100644 fish/functions/ip.fish create mode 100644 fish/functions/src.fish rename fish/{ => os}/linux.fish (100%) create mode 100644 fish/os/os.fish rename fish/{ => os}/osx.fish (100%) diff --git a/fish/apps/autojump.fish b/fish/apps/autojump.fish new file mode 100644 index 0000000..60fd75a --- /dev/null +++ b/fish/apps/autojump.fish @@ -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 diff --git a/fish/fish_startup.in b/fish/apps/iterm2.fish similarity index 100% rename from fish/fish_startup.in rename to fish/apps/iterm2.fish diff --git a/fish/rvm.fish b/fish/apps/rvm.fish similarity index 100% rename from fish/rvm.fish rename to fish/apps/rvm.fish diff --git a/fish/config.fish b/fish/config.fish index 4c1e0da..3678c89 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -2,68 +2,29 @@ # Basics, etc… # ============ -# Default browser +# Default editor set -g -x EDITOR "emacsclient" set -g -x ALTERNATE_EDITOR "vim" -# Add ~/bin to PATH -set -g -x PATH ~/bin $PATH +# Setup PATH +ensure_path ~/bin +ensure_path ~/.emacs.d/bin # Disable Fish greeting banner set --universal fish_greeting -# iTerm2 integration -source ~/.config/fish/fish_startup.in +# Configuration for apps +for app in ~/.config/fish/apps/*.fish + source $app +end # OS-specific configuration -switch (uname) - case Linux - source ~/.config/fish/linux.fish - case Darwin - source ~/.config/fish/osx.fish - case '*' - echo 'Unknown OS. No specifc config' -end +source ~/.config/fish/os/os.fish # Machine-local config if test -e ~/.config/fish/local.fish source ~/.config/fish/local.fish end -# ======= -# Vi Mode -# ======= - -function hybrid_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" - for mode in default insert visual - fish_default_key_bindings -M $mode - end - fish_vi_key_bindings --no-erase -end +# Hybrid Vi Mode set -g fish_key_bindings hybrid_bindings - -# ======== -# 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 - -# ========= -# Functions -# ========= - -function ec - emacsclient -n --alternate-editor=emacs $argv -end - -# IP addresses -function ip - curl icanhazip.com -end - -# reload your Fish config -function src - source ~/.config/fish/config.fish; and clear -end diff --git a/fish/functions/ec.fish b/fish/functions/ec.fish new file mode 100644 index 0000000..9fc5fe7 --- /dev/null +++ b/fish/functions/ec.fish @@ -0,0 +1,4 @@ +# Emacs Client +function ec + emacsclient -n --alternate-editor=emacs $argv +end diff --git a/fish/functions/ensure_path.fish b/fish/functions/ensure_path.fish new file mode 100644 index 0000000..4af8c6d --- /dev/null +++ b/fish/functions/ensure_path.fish @@ -0,0 +1,7 @@ +function ensure_path --description "Ensures directories are in $PATH" + for pathdir in $argv + if not set -l index (contains -i $pathdir $PATH) + set -g -x PATH $pathdir $PATH + end + end +end diff --git a/fish/functions/hybrid_bindings.fish b/fish/functions/hybrid_bindings.fish new file mode 100644 index 0000000..48e2a40 --- /dev/null +++ b/fish/functions/hybrid_bindings.fish @@ -0,0 +1,6 @@ +function hybrid_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" + for mode in default insert visual + fish_default_key_bindings -M $mode + end + fish_vi_key_bindings --no-erase +end diff --git a/fish/functions/ip.fish b/fish/functions/ip.fish new file mode 100644 index 0000000..5d81698 --- /dev/null +++ b/fish/functions/ip.fish @@ -0,0 +1,4 @@ +# Prints current public IP address +function ip + curl icanhazip.com +end diff --git a/fish/functions/src.fish b/fish/functions/src.fish new file mode 100644 index 0000000..71e998b --- /dev/null +++ b/fish/functions/src.fish @@ -0,0 +1,4 @@ +# reload your Fish config +function src + source ~/.config/fish/config.fish; and clear +end diff --git a/fish/linux.fish b/fish/os/linux.fish similarity index 100% rename from fish/linux.fish rename to fish/os/linux.fish diff --git a/fish/os/os.fish b/fish/os/os.fish new file mode 100644 index 0000000..b5a235a --- /dev/null +++ b/fish/os/os.fish @@ -0,0 +1,9 @@ +# OS-specific configuration +switch (uname) + case Linux + source ~/.config/fish/os/linux.fish + case Darwin + source ~/.config/fish/os/osx.fish + case '*' + echo 'Unknown OS. No specifc config' +end diff --git a/fish/osx.fish b/fish/os/osx.fish similarity index 100% rename from fish/osx.fish rename to fish/os/osx.fish