aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2024-01-03 14:30:15 +0100
committerMartin Polden <mpolden@mpolden.no>2024-01-16 10:26:59 +0100
commit7a5ed8ea751110afe551d87aaf15582afe5c54c2 (patch)
treee5657790944bfe7e61f3ae8d95bc89583f76b061
parentfbe6af8f4072aec1e19a36a2fed8c352b1ddf817 (diff)
Revert "Remove fish configuration"
This reverts commit 44768d64e052664e3aceeb2f9c3f332eb16aac2c.
-rw-r--r--Makefile7
-rw-r--r--config.fish183
-rw-r--r--fish_prompt.fish35
3 files changed, 224 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 900179f..c7ed6e4 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ iterm2.conf:
test -f $(ITERM2_PLIST) -a ! -L $(ITERM2_PLIST) && cp -a $(ITERM2_PLIST) $(CURDIR)/iterm2.conf || true
test -e $(CURDIR)/$@ && ln $(LN_FLAGS) $(CURDIR)/$@ $(ITERM2_PLIST)
-install: $(symlinks) iterm2.conf
+install: $(symlinks) iterm2.conf fish
$(symlinks):
test -e $(CURDIR)/$@ && ln $(LN_FLAGS) $(CURDIR)/$@ ~/.$@
@@ -62,6 +62,11 @@ else
$(error could not find a package manager to install $@)
endif
+fish:
+ mkdir -p ~/.config/fish/functions
+ ln $(LN_FLAGS) $(CURDIR)/config.fish ~/.config/fish/config.fish
+ ln $(LN_FLAGS) $(CURDIR)/fish_prompt.fish ~/.config/fish/functions/fish_prompt.fish
+
# Maintenance
print-dead:
diff --git a/config.fish b/config.fish
new file mode 100644
index 0000000..b9e75a3
--- /dev/null
+++ b/config.fish
@@ -0,0 +1,183 @@
+# Helper functions
+function path-prepend
+ set -l p $argv[1]
+ if [ -d $p ]
+ and not contains $p $PATH
+ set -gx PATH $p $PATH
+ end
+end
+
+function cdpath-append
+ set -l p $argv[1]
+ if [ -d $p ]
+ and not contains $p $CDPATH
+ set -gx CDPATH $CDPATH $p
+ end
+end
+
+function is-command
+ command -s $argv[1] > /dev/null
+end
+
+function alias-if-in-path
+ set -l name $argv[1]
+ set -l values (string split ' ' $argv[2])
+ set -l cmd $values[1]
+ if [ $cmd = 'sudo' ]
+ set cmd $values[2]
+ end
+ if is-command $cmd
+ alias $name "$values"
+ end
+end
+
+function ls-command
+ set -l ls_opts '--group-directories-first --color=auto'
+ switch (uname)
+ case Darwin FreeBSD
+ if is-command exa
+ echo "exa $ls_opts"
+ else if is-command gls
+ echo "gls $ls_opts"
+ else if is-command gnuls
+ echo "gnuls $ls_opts"
+ else
+ echo 'ls -G'
+ end
+ case '*'
+ echo "ls $ls_opts"
+ end
+end
+
+function ll-command
+ if is-command exa
+ printf '%s -l\n' (ls-command)
+ else
+ printf '%s -lh\n' (ls-command)
+ end
+end
+
+# Remove greeting
+set fish_greeting
+
+# Prompt
+set -g __fish_git_prompt_color_branch red
+set -g fish_color_user green
+set -g fish_color_host green
+set -g fish_color_at green
+set -g fish_color_cwd blue
+set -g fish_color_command green
+set -g fish_color_param grey
+set -g fish_prompt_pwd_dir_length 0
+
+# Set locale on Darwin
+if [ (uname) = 'Darwin' ]
+ set -gx LANG 'en_US.UTF-8'
+ set -gx LC_CTYPE 'en_US.UTF-8'
+end
+
+# Set terminal inside tmux
+if set -q TMUX
+ set -gx TERM 'screen-256color'
+end
+
+# Set PATH
+path-prepend /usr/local/sbin
+path-prepend /usr/local/bin
+path-prepend $HOME/Library/Python/3.6/bin
+path-prepend $HOME/Library/Python/2.7/bin
+path-prepend /usr/local/go/bin
+path-prepend $HOME/.cargo/bin
+path-prepend $HOME/.local/bin
+
+# Set CDPATH
+cdpath-append .
+cdpath-append $HOME
+cdpath-append $HOME/p
+
+# Configure less
+if is-command lesspipe
+ set -l lesspipe (command -s lesspipe)
+ set -gx LESSOPEN "|$lesspipe %s"
+else if is-command lesspipe.sh
+ set -l lesspipe (command -s lesspipe.sh)
+ set -gx LESSOPEN "|$lesspipe %s"
+end
+
+if is-command less
+ set -gx LESS '-Ri'
+end
+
+# Add colors to man pages
+set -gx LESS_TERMCAP_mb (printf '\e[01;31m')
+set -gx LESS_TERMCAP_md (printf '\e[01;31m')
+set -gx LESS_TERMCAP_me (printf '\e[0m')
+set -gx LESS_TERMCAP_se (printf '\e[0m')
+set -gx LESS_TERMCAP_so (printf '\e[00;47;30m')
+set -gx LESS_TERMCAP_ue (printf '\e[0m')
+set -gx LESS_TERMCAP_us (printf '\e[01;32m')
+
+# Set EDITOR to emacs or vim
+if is-command emacsclient
+ set -gx EDITOR 'emacsclient -q'
+else if is-command emacs
+ set -gx EDITOR 'emacs'
+else if is-command mg
+ set -gx EDITOR 'mg'
+else if is-command vim
+ set -gx EDITOR 'vim'
+end
+
+# Remove mosh prefix from terminal title
+if is-command mosh
+ set -gx MOSH_TITLE_NOPREFIX '1'
+end
+
+# GOPATH
+if [ -d $HOME/go ]
+ set -gx GOPATH $HOME/go
+ path-prepend $GOPATH/bin
+ cdpath-append $GOPATH/src/github.com/mpolden
+end
+
+# JAVA_HOME
+if [ -x /usr/libexec/java_home ]
+ set -l java_home (/usr/libexec/java_home 2> /dev/null)
+ if [ -n $java_home ]
+ set -gx JAVA_HOME $java_home
+ end
+end
+
+# MAVEN_OPTS
+# Prevent Maven from running tasks in the foreground
+if is-command mvn
+ set -gx MAVEN_OPTS '-Djava.awt.headless=true'
+end
+
+# Aliases
+alias git-root 'cd (git rev-parse --show-toplevel)'
+alias week 'date +%V'
+alias ls (ls-command)
+alias ll (ll-command)
+alias-if-in-path grep 'grep --color=auto'
+alias-if-in-path aptup 'sudo apt update; and sudo apt upgrade'
+alias-if-in-path autossh 'autossh -M 0 -o "ServerAliveInterval 10"'
+alias-if-in-path diff 'colordiff'
+alias-if-in-path ec 'emacsclient -nq'
+alias-if-in-path mg 'mg -n'
+
+# Print message if reboot is required
+if status is-interactive > /dev/null
+ and [ -n "$TERM" ]
+ and [ -f /var/run/reboot-required ]
+ echo 'reboot required'
+end
+
+# Local configuration
+if [ -s $HOME/.config/fish/local.fish ]
+ source $HOME/.config/fish/local.fish
+end
+
+# Clean up helper functions
+functions -e path-prepend cdpath-append is-command alias-if-in-path ls-command \
+ ll-command
diff --git a/fish_prompt.fish b/fish_prompt.fish
new file mode 100644
index 0000000..fde66b0
--- /dev/null
+++ b/fish_prompt.fish
@@ -0,0 +1,35 @@
+function fish_prompt --description 'Write out the prompt'
+ if not set -q __fish_prompt_hostname
+ set -g __fish_prompt_hostname (hostname -s)
+ end
+
+ set -q fish_color_at
+ or set -U fish_color_at $normal
+
+ set -l normal (set_color normal)
+ set -l ssh_prefix
+ if set -q SSH_TTY
+ set ssh_prefix (set_color $fish_color_user) $USER \
+ (set_color $fish_color_at) @ (set_color $fish_color_host) \
+ $__fish_prompt_hostname $normal ':'
+ end
+
+ # Display fancy symbol on darwin
+ set __prompt_symbol '$'
+ if [ -z "$EMACS" -a (uname) = 'Darwin' ]
+ set -l burger (echo -ne '\xF0\x9F\x8D\x94')
+ set -l coffee (echo -ne '\xE2\x98\x95')
+ set -l beer (echo -ne '\xF0\x9F\x8D\xBA')
+ set -l hour (date +%-k)
+ if [ $hour -ge 8 -a $hour -lt 16 ]
+ set __prompt_symbol "$coffee "
+ else if [ $hour -ge 16 -a $hour -lt 19 ]
+ set __prompt_symbol "$burger "
+ else
+ set __prompt_symbol "$beer "
+ end
+ end
+
+ echo -n -s $ssh_prefix (set_color $fish_color_cwd) (prompt_pwd) \
+ $normal (__fish_git_prompt ' %s') $normal $__prompt_symbol ' '
+end