fish: overhaul config
This commit is contained in:
parent
2c16fc885c
commit
9ace128d40
@ -4,7 +4,7 @@ My personal configuration files.
|
||||
|
||||
##### Usage
|
||||
|
||||
1. Clone this repository into `~/.dotfiles`
|
||||
1. Clone this repository into `~/dotfiles`
|
||||
2. Install [Homebrew](https://brew.sh/): `./install-brew.sh`
|
||||
3. Install tools: `brew bundle install --file=brew/Brewfile`
|
||||
4. (Optional) Install more tools: `brew bundle install --file=brew/Brewfile.opt`
|
||||
|
@ -24,8 +24,9 @@ alias afk='pmset displaysleepnow'
|
||||
alias dnsflush='sudo killall -HUP mDNSResponder'
|
||||
alias java8="export JAVA_HOME=$JAVA_HOME_8"
|
||||
alias java11="export JAVA_HOME=$JAVA_HOME_11"
|
||||
alias md5sum="md5 -r $argv"
|
||||
alias md5sum="md5 -r"
|
||||
alias vi='nvim'
|
||||
alias vim='nvim'
|
||||
|
||||
# Do not save lines which begin with a space character
|
||||
# Do not save lines which match the previous history entry
|
||||
|
3
fish/.gitignore
vendored
3
fish/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
fish_variables
|
||||
fisher/
|
||||
fisher.fish
|
||||
fish_user_key_bindings.fish
|
||||
fzf_key_bindings.fish
|
||||
|
@ -4,15 +4,38 @@ set fish_greeting
|
||||
# Disable the abbreviated directory format
|
||||
set fish_prompt_pwd_dir_length 0
|
||||
|
||||
# Set global variables
|
||||
# Environment variables
|
||||
set -x EDITOR nvim
|
||||
set -x LANG en_US.UTF-8
|
||||
set -x MANPAGER 'nvim +Man!'
|
||||
set -x FZF_DEFAULT_COMMAND 'fd --type f'
|
||||
set -x FZF_DEFAULT_OPTS '--height=40% --layout=reverse'
|
||||
set -x JAVA_HOME (/usr/libexec/java_home -v 1.8)
|
||||
set -x SBT_OPTS '-Dsbt.supershell=false'
|
||||
|
||||
# FZF (https://github.com/junegunn/fzf)
|
||||
set -x FZF_DEFAULT_OPTS "--height=40% --layout=reverse --multi"
|
||||
set -x FZF_DEFAULT_COMMAND "fd --type=file"
|
||||
set -x FZF_CTRL_T_COMMAND "fd --type=file --follow"
|
||||
set -x FZF_CTRL_T_OPTS "--ansi --no-height --preview 'bat --color=always {}'"
|
||||
set -x FZF_CTRL_R_OPTS "--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
|
||||
set -x FZF_ALT_C_COMMAND "fd --type=directory --follow"
|
||||
set -x FZF_ALT_C_OPTS "--preview 'tree -C {} | head -200'"
|
||||
|
||||
# Git prompt
|
||||
set -g __fish_git_prompt_showdirtystate 1
|
||||
set -g __fish_git_prompt_showstashstate 1
|
||||
set -g __fish_git_prompt_showuntrackedfiles 1
|
||||
set -g __fish_git_prompt_showupstream 'informative'
|
||||
set -g __fish_git_prompt_char_upstream_ahead '↑'
|
||||
set -g __fish_git_prompt_char_upstream_behind '↓'
|
||||
set -g __fish_git_prompt_char_upstream_prefix ' '
|
||||
set -g __fish_git_prompt_color_branch magenta
|
||||
set -g __fish_git_prompt_color_dirtystate cyan
|
||||
set -g __fish_git_prompt_color_invalidstate red
|
||||
set -g __fish_git_prompt_color_stagedstate cyan
|
||||
set -g __fish_git_prompt_color_stashstate cyan
|
||||
set -g __fish_git_prompt_color_untrackedfiles cyan
|
||||
set -g __fish_git_prompt_color_upstream yellow
|
||||
|
||||
# Path
|
||||
set --erase PATH
|
||||
test -d $HOME/bin ; and set -x PATH $HOME/bin
|
||||
@ -24,24 +47,22 @@ test -d /usr/sbin ; and set -x PATH $PATH /usr/sbin
|
||||
test -d /sbin ; and set -x PATH $PATH /sbin
|
||||
|
||||
# Aliases
|
||||
alias adventure='emacs -batch -l dunnet'
|
||||
alias afk='pmset displaysleepnow'
|
||||
alias md5sum="md5 -r $argv"
|
||||
alias sha256sum="shasum -a 256 $argv"
|
||||
alias md5sum='md5 -r'
|
||||
alias sha256sum='shasum -a 256'
|
||||
alias vi='nvim'
|
||||
alias vim='nvim'
|
||||
|
||||
# Install package manager if needed
|
||||
if not functions -q fisher
|
||||
curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
|
||||
fish -c fisher
|
||||
end
|
||||
|
||||
# Set package installation folder
|
||||
# Fish package manager
|
||||
set -g fisher_path ~/.config/fish/fisher
|
||||
|
||||
# Add packages to fish config
|
||||
set fish_function_path $fish_function_path[1] $fisher_path/functions $fish_function_path[2..-1]
|
||||
set fish_complete_path $fish_complete_path[1] $fisher_path/completions $fish_complete_path[2..-1]
|
||||
for file in $fisher_path/conf.d/*.fish
|
||||
builtin source $file 2> /dev/null
|
||||
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
|
||||
echo "Installing fish-shell packages..."
|
||||
fish -c fisher
|
||||
end
|
||||
|
@ -1,2 +1,4 @@
|
||||
jorgebucaran/fish-bax
|
||||
jorgebucaran/fish-nvm
|
||||
oh-my-fish/plugin-license
|
||||
oh-my-fish/plugin-sublime
|
||||
|
@ -1,5 +0,0 @@
|
||||
function _set_global_if_unset --argument-names variable_name variable_value
|
||||
if not set --query $variable_name
|
||||
set --global $variable_name $variable_value
|
||||
end
|
||||
end
|
@ -1,12 +0,0 @@
|
||||
function brew_install --description "Select packages to install"
|
||||
set --local inst_pkgs $argv
|
||||
|
||||
if test (count $inst_pkgs) -eq 0
|
||||
set inst_pkgs (brew search | eval "fzf --multi --prompt='[brew:install] '")
|
||||
end
|
||||
|
||||
if test (count $inst_pkgs) -gt 0
|
||||
echo "Installing: $inst_pkgs"
|
||||
brew install $inst_pkgs
|
||||
end
|
||||
end
|
@ -1,49 +0,0 @@
|
||||
function brew_uninstall --description "Select packages to uninstall"
|
||||
set --local uninst_pkgs $argv
|
||||
|
||||
if test (count $uninst_pkgs) -eq 0
|
||||
set uninst_pkgs (brew leaves | eval "fzf --multi --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 uninst_pkgs and their transitive dependencies
|
||||
set --local uninst_pkgs_all $uninst_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
|
||||
end
|
||||
|
||||
# Don't uninstall packages that are still dependencies of other 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
|
||||
|
||||
echo "Uninstalling: $uninst_pkgs_final"
|
||||
brew uninstall $uninst_pkgs_final
|
||||
end
|
||||
end
|
@ -1,8 +1,8 @@
|
||||
function _confirmation --description "Ask for user confirmation"
|
||||
function confirm --description "Ask for user confirmation"
|
||||
while true
|
||||
read --local --prompt-str='Are you sure you want to continue? [y/N] ' confirm
|
||||
read --local --prompt-str='Are you sure you want to continue? [y/N] ' confirmed
|
||||
|
||||
switch $confirm
|
||||
switch $confirmed
|
||||
case Y y
|
||||
return 0
|
||||
case '' N n
|
78
fish/functions/fbrew.fish
Normal file
78
fish/functions/fbrew.fish
Normal file
@ -0,0 +1,78 @@
|
||||
function fbrew --description "Fuzzy homebrew"
|
||||
if test (count $argv) -eq 0
|
||||
echo "Usage: fbrew <install|uninstall>"
|
||||
return 1
|
||||
end
|
||||
|
||||
switch $argv[1]
|
||||
case i install
|
||||
_fbrew_install $argv[2..-1]
|
||||
case u uninstall
|
||||
_fbrew_uninstall $argv[2..-1]
|
||||
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
|
||||
|
||||
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 uninst_pkgs and their transitive dependencies
|
||||
set --local uninst_pkgs_all $uninst_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
|
||||
end
|
||||
|
||||
# Don't uninstall packages that are still dependencies of other 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
|
||||
|
||||
echo "Uninstalling: $uninst_pkgs_final"
|
||||
brew uninstall $uninst_pkgs_final
|
||||
end
|
||||
end
|
@ -7,8 +7,7 @@ function fish_prompt --description 'Write out the prompt'
|
||||
echo -n (prompt_pwd)
|
||||
set_color normal
|
||||
|
||||
# Print Git information
|
||||
fish_prompt_git_settings
|
||||
# Print git information
|
||||
printf '%s ' (__fish_git_prompt)
|
||||
|
||||
# Print status code for previous command, if nonzero
|
||||
@ -18,6 +17,6 @@ function fish_prompt --description 'Write out the prompt'
|
||||
set_color normal
|
||||
end
|
||||
|
||||
# Print the final character (§)
|
||||
# Print the final character
|
||||
echo -n "> "
|
||||
end
|
||||
|
@ -1,21 +0,0 @@
|
||||
function fish_prompt_git_settings --description 'Configure the git prompt'
|
||||
# Toggles
|
||||
_set_global_if_unset __fish_git_prompt_showdirtystate 1
|
||||
_set_global_if_unset __fish_git_prompt_showstashstate 1
|
||||
_set_global_if_unset __fish_git_prompt_showuntrackedfiles 1
|
||||
_set_global_if_unset __fish_git_prompt_showupstream "informative"
|
||||
|
||||
# Characters
|
||||
_set_global_if_unset __fish_git_prompt_char_upstream_ahead '↑'
|
||||
_set_global_if_unset __fish_git_prompt_char_upstream_behind '↓'
|
||||
_set_global_if_unset __fish_git_prompt_char_upstream_prefix ' '
|
||||
|
||||
# Colors
|
||||
_set_global_if_unset __fish_git_prompt_color_branch magenta
|
||||
_set_global_if_unset __fish_git_prompt_color_dirtystate cyan
|
||||
_set_global_if_unset __fish_git_prompt_color_invalidstate red
|
||||
_set_global_if_unset __fish_git_prompt_color_stagedstate cyan
|
||||
_set_global_if_unset __fish_git_prompt_color_stashstate cyan
|
||||
_set_global_if_unset __fish_git_prompt_color_untrackedfiles cyan
|
||||
_set_global_if_unset __fish_git_prompt_color_upstream yellow
|
||||
end
|
32
fish/functions/fkill.fish
Normal file
32
fish/functions/fkill.fish
Normal file
@ -0,0 +1,32 @@
|
||||
function fkill --description "Fuzzy kill processes"
|
||||
#
|
||||
# Signal Numbers:
|
||||
#
|
||||
# 1 HUP (hang up)
|
||||
# 2 INT (interrupt)
|
||||
# 3 QUIT (quit)
|
||||
# 6 ABRT (abort)
|
||||
# 9 KILL (non-catchable, non-ignorable kill)
|
||||
# 14 ALRM (alarm clock)
|
||||
# 15 TERM (software termination signal)
|
||||
#
|
||||
|
||||
set --local fkill_uid (id -u)
|
||||
set --local fkill_pid
|
||||
set --local fkill_procs
|
||||
|
||||
if contains -- '--tcp' $argv
|
||||
set fkill_pid (lsof -Pwni tcp | sed 1d | eval "fzf --prompt='[kill:tcp] '" | awk '{print $2}')
|
||||
else
|
||||
if test $fkill_uid -eq 0
|
||||
set fkill_procs (ps -ef | tail -n +2 | string collect)
|
||||
else
|
||||
set fkill_procs (ps -f -u $fkill_uid | tail -n +2 | string collect)
|
||||
end
|
||||
set fkill_pid (echo $fkill_procs | eval "fzf --prompt='[kill:process] ' --preview='ps -p {2}' --preview-window='down:3'" | awk '{print $2}')
|
||||
end
|
||||
|
||||
if test (count $fkill_pid) -gt 0
|
||||
echo $fkill_pid | xargs kill -9
|
||||
end
|
||||
end
|
3
fish/functions/jira.fish
Normal file
3
fish/functions/jira.fish
Normal file
@ -0,0 +1,3 @@
|
||||
function jira
|
||||
open "https://track.akamai.com/jira/browse/"$argv[1]
|
||||
end
|
@ -1,17 +0,0 @@
|
||||
function kp --description "Kill processes"
|
||||
set --local __kp__pid ''
|
||||
|
||||
if contains -- '--tcp' $argv
|
||||
set __kp__pid (lsof -Pwni tcp | sed 1d | eval "fzf --multi --prompt='[kill:tcp] '" | awk '{print $2}')
|
||||
else
|
||||
set __kp__pid (ps -ef | sed 1d | eval "fzf --multi --prompt='[kill:process] '" | awk '{print $2}')
|
||||
end
|
||||
|
||||
if test "x$__kp__pid" != "x"
|
||||
if test "x$argv[1]" != "x"
|
||||
echo $__kp__pid | xargs kill $argv[1]
|
||||
else
|
||||
echo $__kp__pid | xargs kill -9
|
||||
end
|
||||
end
|
||||
end
|
@ -1,13 +0,0 @@
|
||||
function path_search --description "Search your path for an executable"
|
||||
set --local loc (echo $PATH | tr ' ' '\n' | eval "fzf --prompt='[find:path] '")
|
||||
|
||||
if test (count $loc) = 1
|
||||
set --local cmd (rg --files -L $loc | rev | cut -d'/' -f1 | rev | tr ' ' '\n' | eval "fzf --preview='head -20 $loc/{}' --prompt='[find:exe] '")
|
||||
if test (count $cmd) = 1
|
||||
echo $cmd
|
||||
else
|
||||
path_search
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
function pip3_upgrade --description "Upgrade python packages (pip3)"
|
||||
function pip_upgrade --description "Upgrade python packages"
|
||||
set --local py_pkgs_outdated (pip3 list --outdated | awk 'NR > 2 {print $1}')
|
||||
|
||||
if test (count $py_pkgs_outdated) = 0
|
||||
|
7
fish/functions/port_listener.fish
Normal file
7
fish/functions/port_listener.fish
Normal file
@ -0,0 +1,7 @@
|
||||
function port_listener --argument-names port
|
||||
if test -n "$port"
|
||||
lsof -n -i :$port | rg LISTEN
|
||||
else
|
||||
lsof -n -i | rg LISTEN
|
||||
end
|
||||
end
|
@ -1,7 +0,0 @@
|
||||
function portlistener --argument-names port
|
||||
if test -n "$port"
|
||||
lsof -n -i :$port | grep LISTEN
|
||||
else
|
||||
lsof -n -i | grep LISTEN
|
||||
end
|
||||
end
|
17
fish/functions/pull_request.fish
Normal file
17
fish/functions/pull_request.fish
Normal file
@ -0,0 +1,17 @@
|
||||
function pull_request --argument-names target_branch source_branch
|
||||
if test -z "$target_branch"
|
||||
set target_branch (git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
|
||||
echo "Using default branch as target: "$target_branch
|
||||
end
|
||||
if test -z "$source_branch"
|
||||
set source_branch (git branch --show-current)
|
||||
echo "Using current branch as source: "$source_branch
|
||||
end
|
||||
|
||||
# Format: ssh://git@git.source.akamai.com:7999/<project>/<repo>.git
|
||||
set --local origin (git remote get-url origin)
|
||||
set --local project (string split -r -m2 '/' $origin)[-2]
|
||||
set --local repo (basename -s .git $origin)
|
||||
|
||||
open "https://git.source.akamai.com/projects/"$project"/repos/"$repo"/compare/commits?sourceBranch=refs%2Fheads%2F"$source_branch"&targetBranch=refs%2Fheads%2F"$target_branch
|
||||
end
|
@ -29,7 +29,8 @@
|
||||
cand = commit --amend --no-edit --date=now
|
||||
rbi = rebase --interactive
|
||||
re = restore
|
||||
rh = reset HEAD
|
||||
res = restore --staged
|
||||
rh = reset -q HEAD --
|
||||
[color]
|
||||
ui = auto
|
||||
[color "branch"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
DOTFILES="$HOME/.dotfiles"
|
||||
DOTFILES="$HOME/dotfiles"
|
||||
|
||||
# Create required directories before making links
|
||||
mkdir -p "$HOME/.config"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
DOTFILES="$HOME/.dotfiles"
|
||||
DOTFILES="$HOME/dotfiles"
|
||||
|
||||
# Install plugin manager for Neovim, if it doesn't exist
|
||||
VIM_PLUG_SRC="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
|
||||
@ -15,7 +15,7 @@ grep -q /usr/local/bin/bash /etc/shells || echo /usr/local/bin/bash | sudo tee -
|
||||
grep -q /usr/local/bin/fish /etc/shells || echo /usr/local/bin/fish | sudo tee -a /etc/shells
|
||||
|
||||
# Make fish the default shell
|
||||
chsh -s /usr/local/bin/fish
|
||||
sudo chsh -s /usr/local/bin/fish `whoami`
|
||||
|
||||
# Install symlinks
|
||||
"$DOTFILES/install-symlinks.sh"
|
||||
|
Loading…
x
Reference in New Issue
Block a user