Skip to content

Instantly share code, notes, and snippets.

@mopemope
Created August 24, 2016 22:59
Show Gist options
  • Save mopemope/e72cc4ae6df234a3f0c59638aa86d8b3 to your computer and use it in GitHub Desktop.
Save mopemope/e72cc4ae6df234a3f0c59638aa86d8b3 to your computer and use it in GitHub Desktop.
2016 config.fish
set fish_greeting ""
set -x LC_CTYPE ja_JP.UTF-8
set -x LANG ja_JP.UTF-8
set -x ANSIBLE_NOCOWS 1
set -x EDITOR emacsclient
set -x LOLCOMMITS_FORK true
set -x FZF_DEFAULT_COMMAND 'ag -g ""'
set -x FZF_DEFAULT_OPTS '--ansi --inline-info'
set -x JAVA_HOME /usr/lib/jvm/default
set -x ANT_HOME "$HOME/opt/ant"
# set -x MVN_HOME "$HOME/opt/maven"
# set -x M2_HOME "$HOME/opt/maven"
set -x GOROOT "$HOME/opt/go"
set -x GOPATH "$HOME/go"
set -x RUST_SRC_PATH "$HOME/src/rustc-1.9.0/src"
set -x CARGO_HOME "$HOME/.cargo"
set -gx PATH $HOME/bin $GOROOT/bin $GOPATH/bin $JAVA_HOME/bin $HOME/google-cloud-sdk/bin $HOME/.gem/ruby/2.2.0/bin/ $HOME/.local/bin $CARGO_HOME/bin $PATH
alias tmux "tmux -2"
alias tm "tmux -2"
alias tma "tmux attach"
alias tml "tmux list-window"
alias g "git"
alias v "vim -X"
function fzf_select_history
history|fzf|read slct
if [ $slct ]
commandline $slct
else
commandline ''
end
end
function fish_user_key_bindings
bind \cx __exit
bind \cr fzf_select_history
end
function gcd
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
ghq list -p|fzf -q $q|read slct
if [ $slct ]
cd $slct
end
end
function fkill
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
ps -ef|sed 1d|fzf -q $q|awk '{print $2}'|read slct
if [ $slct ]
kill -9 $slct
end
end
function fps
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
ps -ef|sed 1d|fzf -q $q|awk '{print $2}'|read slct
if [ $slct ]
echo $slct
end
end
function fstrace
ps -ef|sed 1d|fzf|awk '{print $2}'|read slct
if [ $slct ]
sudo strace -tt -s 1024 $argv -p $slct
end
end
function cdf
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
fzf -q $q|read file
if [ $file ]
set -l dir (dirname $file)
if [ $dir ]
cd $dir
end
end
end
function gco
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
git branch --all | grep -v HEAD | fzf -1 -q $q | read slct
if [ $slct ]
git checkout (echo "$slct" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
end
end
function gpush
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
git branch -r | grep -v HEAD | fzf -1 -q $q | read slct
if [ $slct ]
eval git push -v (echo $slct | sed "s/\// /")
end
end
function gpull
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
git branch -r | grep -v HEAD | fzf -1 -q $q | read slct
if [ $slct ]
eval git pull -v (echo $slct | sed "s/\// /")
end
end
function gl
git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" $argv | \
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--preview "echo {} | grep -o '[a-f0-9]\{7\}' | head -1 | xargs -I '%s' sh -c 'git show --color=always '%s' | head -$LINES '" \
--bind "ctrl-m:execute:echo {} | grep -o '[a-f0-9]\{7\}' | head -1 | xargs -I '%s' sh -c 'git show --color=always '%s'' "
end
function git-today
git log --author='Yutaka Matsubara' --since=midnight --numstat --pretty="%H" | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
end
function e
set -l arg $argv[1]
set -l cmd "emacs"
if [ (pgrep -x -u $USER emacs) ]
set cmd "emacsclient"
end
if test -e $arg
eval $cmd $arg "&"
return
else
if echo $arg | grep -q -E '\.\w+$'
eval $cmd $arg "&"
return
end
set -l q ""
if [ $arg ]
set q $arg
end
fzf -q $q | read file
if [ $file ]
eval $cmd $file "&"
end
end
end
function timer
set -l t $argv[1]
set -l msg $argv[2]
set -l interval (math "$t * 60")
sleep $interval
notify-send -u critical "Notify " "$msg "
end
function clean_docker
sudo docker rm -v (sudo docker ps -a -q)
sudo docker rmi (sudo docker images | awk '/^<none>/ { print $3 }')
end
function drmi
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
sudo docker images|sed -e '1d'|fzf -q $q|read slct
if [ $slct ]
sudo docker rmi (echo $slct | awk '// { print $3 }')
end
end
function drm
set -l q ""
if [ $argv[1] ]
set q $argv[1]
end
sudo docker ps -a|sed -e '1d'|fzf -q $q|read slct
if [ $slct ]
echo $drm
sudo docker rm -v (echo $slct | awk '// { print $1 }')
end
end
function _gb
if test -e "src" -a -e "vendor"
set -l gopath (pwd):(pwd)/vendor
set -gx GOPATH $gopath
set -gx GB_PROJECT (pwd)
else
if test $GB_PROJECT
set -l path (pwd)
set -l gb $GB_PROJECT
switch $path
case "*$gb*"
case "*"
set -e GB_PROJECT
set -gx GOPATH "$HOME/go"
end
else
set -gx GOPATH "$HOME/go"
end
end
end
function chpwd --on-variable PWD
status --is-command-substitution; and return
_gb
ll
end
if [ (pgrep -x -u $USER gpg-agent) ]
else
gpg-connect-agent /bye >/dev/null 2>&1
end
set -e SSH_AGENT_PID
set -e SSH_ASKPASS
set -x SSH_AUTH_SOCK "$HOME/.gnupg/S.gpg-agent.ssh"
# Set GPG TTY
set -x GPG_TTY (tty)
source ~/.config/fish/nvm-wrapper/nvm.fish
nvm use --silent default
source ~/.enhancd/fish/enhancd.fish
alias ecd cd::cd
if status --is-login
set -l host (hostname)
set PPID (echo (ps --pid %self -o ppid --no-headers) | xargs)
if ps --pid $PPID | grep ssh
tmux has-session -t $host; and tmux attach-session -t $host; or tmux new-session -s $host; and kill %self
echo "tmux failed to start; using plain fish shell"
end
end
if not set -q AUTOENVFISH_FILE
set -g AUTOENVFISH_FILE ".env.fish"
end
function _autoenvfish --on-variable PWD
if status --is-command-substitution
return
end
set -l envfishdir $PWD
while test ! "$envfishdir" = "" -a ! -f "$envfishdir/$AUTOENVFISH_FILE"
set envfishdir (echo "$envfishdir" | sed 's|/[^/]*$||')
end
set -l envfishpath "$envfishdir/$AUTOENVFISH_FILE"
if [ $envfishpath != "$AUTOENVFISH" ]
if [ -f $envfishpath ]
set -gx AUTOENVFISH $envfishpath
else
set -ex AUTOENVFISH
end
end
end
function _source_envfish --on-variable AUTOENVFISH
if [ -f "$AUTOENVFISH" ]
echo "loading $AUTOENVFISH"
. $AUTOENVFISH
end
end
# prompt
function _hg_branch_name
echo (command hg branch ^/dev/null)
end
function _is_hg_dirty
echo (command hg status ^/dev/null)
end
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
set -l red (set_color red)
set -l yellow (set_color FFFF99)
set -l blue (set_color 1E90FF)
set -l green (set_color green)
set -l cyan (set_color cyan)
set -l normal (set_color normal)
set -l arrow "λ"
set -l host (hostname)
set -l cwd $blue(basename (prompt_pwd))
if [ $SSH_CONNECTION ]
set arrow $red $arrow
end
if [ (_git_branch_name) ]
set git_info $green(_git_branch_name)
set vcs_info ":$git_info"
if [ (_is_git_dirty) ]
set -l dirty "*"
set vcs_info "$vcs_info$dirty"
end
else
if [ (_hg_branch_name) ]
set hg_info $cyan(_hg_branch_name)
set vcs_info ":$hg_info"
if [ (_is_hg_dirty) ]
set -l dirty "*"
set vcs_info "$vcs_info$dirty"
end
end
end
echo -n -s $cwd $vcs_info $normal ' ' $arrow ' '
end
function fish_right_prompt
set -l blue (set_color 00BFFF)
set_color $fish_color_autosuggestion ^/dev/null; or set_color 555
date "+%H:%M:%S"
set_color normal
echo $blue (hostname)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment