Skip to content

Instantly share code, notes, and snippets.

@mopemope
Last active June 23, 2022 11:37
Show Gist options
  • Save mopemope/2fc28d3347dc8fd82ab7 to your computer and use it in GitHub Desktop.
Save mopemope/2fc28d3347dc8fd82ab7 to your computer and use it in GitHub Desktop.
config.fish
# Path to Oh My Fish install.
set -gx OMF_PATH /home/ma2/.local/share/omf
# Customize Oh My Fish configuration path.
#set -gx OMF_CONFIG /home/ma2/.config/omf
set fish_plugins pbcopy
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_OPTS '-Dswank.encoding=utf-8-unix'
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 -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 $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
ghq list -p|fzf|read slct
if [ $slct ]
cd $slct
end
end
function fkill
ps -ef|sed 1d|fzf|awk '{print $2}'|read slct
if [ $slct ]
kill -9 $slct
end
end
function fps
ps -ef|sed 1d|fzf|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
git branch --all | grep -v HEAD|fzf|read slct
if [ $slct ]
git checkout (echo "$slct" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
end
end
function gpush
git branch -r | grep -v HEAD|fzf|read slct
if [ $slct ]
eval git push -v (echo $slct | sed "s/\// /")
end
end
function gpull
git branch -r | grep -v HEAD|fzf|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 --toggle-sort=\` --bind "ctrl-m:execute: echo '{}' | grep -o '[a-f0-9]\{7\}' | head -1 | xargs -I % sh -c 'git show --color=always % | less -R'"
end
function e
set -l arg $argv[1]
set -l cmd "emacs -fs "
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 _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)
# Load oh-my-fish configuration.
source $OMF_PATH/init.fish
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