Skip to content

Instantly share code, notes, and snippets.

@pid
Forked from victorporof/config.fish.sh
Created April 19, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pid/ac2b1d52a3e0d76aba23ca4c4cf04e5f to your computer and use it in GitHub Desktop.
Save pid/ac2b1d52a3e0d76aba23ca4c4cf04e5f to your computer and use it in GitHub Desktop.
config.fish
# Fish 2.0 config
# Enviroment setup
clear
set -x NODE_PATH /usr/local/lib/node_modules
set -x PATH /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbin /usr/local/share/npm/bin $NODE_PATH
set -e fish_greeting
alias @ "printf '%s'"
alias @@ "xargs printf '%s'"
alias @% "xargs printf"
set _black (set_color black)
set _black_bkg (set_color --background black)
set _green (set_color green)
set _brown (set_color brown)
set _yellow (set_color yellow)
set _blue (set_color blue)
set _magenta (set_color magenta)
set _purple (set_color purple)
set _red (set_color red)
set _cyan (set_color cyan)
set _white (set_color white)
set _normal (set_color normal)
set _normal_bkg (set_color --background normal)
set _bold (set_color --bold)
set _underline (set_color --underline)
# Directories
set DESKTOP $HOME/Desktop
set DROPBOX $HOME/Dropbox
set DOWNLOADS $HOME/Downloads
# Git
alias gs "git status --short"
alias gd "git diff --color-words"
set pretty_oneline "%C(red)%h%C(auto)%d%C(reset) %s %C(green)(%cr) %C(blue dim)<%an>%C(reset)"
set pretty_full "%C(yellow)commit %C(red)%H%C(auto)%d%n%C(reset)Author: %C(blue)%an %C(blue dim)<%ae>%n%C(reset)Date: %C(green)%ad %C(green dim)(%cr)%n%n%C(normal bold)%w(0,4,4)%s%n%n%C(normal)%w(0,4,4)%b%C(reset)%n"
alias glg "git log --graph --stat --max-count=1 --pretty=format:'$pretty_full'"
alias glgg "git log --graph --pretty=format:'$pretty_oneline'"
alias gl "git pull --rebase"
alias glup "git pull upstream master --rebase"
alias gp "git push"
alias gpf "git push --force"
alias ga "git add"
alias gc "git commit --signoff --message"
alias gca "git commit --signoff --amend --no-edit"
alias gcam "git commit --signoff --amend --message"
alias gst "git stash save"
alias gsta "git stash save --include-untracked"
alias gsti "git stash save --patch"
alias gsl "git stash list"
alias gss "git stash show --patch"
alias gsp "git stash pop"
alias gsa "git stash apply"
alias gsd "git stash drop"
alias gsda "git stash clear"
# Remove untracked files from the working tree.
alias gpur "git clean --force"
# Unstage all files from the index.
alias gr "git reset --mixed"
# Reset to commit, leaving staged files and working tree intact.
alias grs "git reset --soft"
# Unstage all files from the index and reset uncommitted changes.
alias gra "git reset --hard; git status --short"
# Unstage all files, reset uncommitted changes and purge untracked files.
alias grap "git reset --hard; git clean --force; git status --short"
# Unstage all files, reset uncommitted changes, purge untracked files and checkout to master.
alias grapp "git reset --hard; git clean --force; git checkout master; git status --short"
alias gb "git branch"
alias gba "git branch --all"
alias gco "git checkout"
alias gcm "git checkout master"
alias gnew "git checkout -b"
alias gm "git merge"
alias grb "git rebase"
alias grc "git rebase --continue"
alias grab "git rebase --abort"
function grbi --description "Interactive rebase branch from the base"
set branch (git symbolic-ref --quiet HEAD | cut -d "/" -f 3)
set base (git merge-base $branch master)
git rebase --interactive $base
end
function gbd --description "Deletes a branch locally and at origin"
git branch --delete --force $argv[1]
git push origin --delete $argv[1]
end
function gmpr --description "Merge a pull request"
# TODO
end
# Mercurial
alias hgs "hg status"
alias hgsq "hg status -m -a -r -d"
alias hgd "hg diff"
alias hgg "hg log --rev (hg parent --template \"{node}\") --stat"
alias hggg "hg log --graph --limit 20"
alias hgu "hg update"
alias hgl "hg pull --update"
alias hgp "hg push"
alias hgpf "hg push --force"
alias hga "hg add"
alias hgar "hg addremove"
alias hgc "hg commit"
alias hgca "hg qimport --rev tip; hg qrefresh --edit; hg qfinish tip"
# Remove untracked files from the working tree.
alias hgpur "hg purge"
# Reset uncommitted changes.
alias hgra "hg revert --all"
# Reset uncommitted changes and purge untracked files.
alias hgrap "hg revert --all; hg purge"
# Reset uncommitted changes, purge untracked files and pop all the queue.
alias hgrapp "hg revert --all; hg purge; hg qpop --all"
alias hgb "hg branch"
alias hgba "hg branches"
alias hgco "hg checkout"
alias hgm "hg merge"
alias hgrb "hg rebase"
# Mercurial queues
alias qnew "hg qnew --force"
alias qimp "hg qimport"
alias qfol "hg qfold"
alias qfin "hg qfinish --applied"
alias qrm "hg qremove"
alias qrn "hg qrename"
alias qref "hg diff; hg qref"
alias qrefm "hg qref --message"
alias qrefe "hg qref --edit"
alias qrefu "hg qref --user"
alias qpu "hg qpush"
alias qpm "hg qpush --move"
alias qpo "hg phase --force --draft qbase:tip; hg qpop"
alias qpa "hg phase --force --draft qbase:tip; hg qpop --all"
alias qgo "hg qgoto"
alias qcref "hg qcrefresh"
alias qdiff "hg qdiff"
alias qser "hg qseries --summary --verbose"
alias qa "hg qa --summary --verbose"
alias qu "hg qu --summary --verbose"
function qexp --description "Export the current qtip as a patch on the desktop"
hgg
set qtip (hg qa | tail -1)
if [ $qtip ]
set file $DESKTOP/$qtip
hg export qtip > $file
ls -lah $file | awk '{ print $5 }'
end
end
function hgqpl --description "Pop all the queue, pull, update and restore queue"
if [ (: hgsq) ]
hgs
return
end
set qtip (hg qa | tail -1)
if [ $qtip ]
qpa
end
hgl
hg pushlogsync
hggg
if [ $qtip ]
qpu $qtip
end
end
function hgback --description "Perform a mercurial backout without a merge"
if [ (count $argv) = 0 ]
set tip (hg tip --template "{rev}")
hgback $tip
return
end
if [ (count $argv) = 1 ]
set cset $argv[1]
set parent (hg parent --rev $cset --template "{rev}")
hgback $cset $parent
return
end
set newest $argv[1]
set oldest $argv[2]
set file "backout-$newest.patch"
hgd --rev $newest:$oldest > $file
qimp --force --push $file
set node (hg log --rev $newest --template "{node|short}")
qrefm "Backed out changeset $node"
hgg
rm $file
end
# Utility functions
function :ip --description "What is my IP?"
dig +short myip.opendns.com @resolver1.opendns.com
end
function ftp --description "Start a ftp server"
sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
end
function ftpstop --description "Stop a ftp server"
sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
end
function sser --description "Starts a SimpleHTTPServer in the current directory"
if [ (count $argv) = 0 ]
sser 8080
return
end
python -m SimpleHTTPServer $argv[1]
end
function sser_utf8 --description "Starts a SimpleHTTPServer in the current directory serving utf-8 encoded files"
python -c "import SimpleHTTPServer; m = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map; m[''] = 'text/plain'; m.update(dict([(k, v + ';charset=UTF-8') for k, v in m.items()])); SimpleHTTPServer.test();"
end
function pman --description "Open a man page in Preview"
man -t $argv[1] | open -f -a Preview
end
function sman --description "Open a man page in Sublime Text"
man $argv[1] | col -b | subl
end
function sman --description "Open a man page in Atom"
man $argv[1] | col -b | atom
end
function :mem --description "Quickly check what is eating all your memory"
top -o vsize
end
function :cpu --description "Quickly check what is eating all your cpu"
top -o cpu
end
function : --description "Checks if a statement executes cleanly, and prints the result if so"
@ (eval $argv ^/dev/null)
end
# Firefox dev
set MOZCONFIG $HOME/.mozconfig-firefox
set CCACHE_DIR $HOME/.ccache
set HG_FX ssh://hg.mozilla.org/integration/fx-team
set HG_MI ssh://hg.mozilla.org/integration/mozilla-inbound
set HG_MC ssh://hg.mozilla.org/mozilla-central
set HG_MA ssh://hg.mozilla.org/releases/mozilla-aurora
set HG_MB ssh://hg.mozilla.org/releases/mozilla-beta
set HG_MR ssh://hg.mozilla.org/releases/mozilla-release
set HG_TRY ssh://hg.mozilla.org/try
set MOZDEV ~/Work/Mozilla
set FXTEAM ~/Work/Mozilla/fx-team
set GUM ~/Work/Mozilla/gum
set M_INBOUND ~/Work/Mozilla/mozilla-inbound
set M_CENTRAL ~/Work/Mozilla/mozilla-central
set M_AURORA ~/Work/Mozilla/mozilla-aurora
set M_BETA ~/Work/Mozilla/mozilla-beta
set M_RELEASE ~/Work/Mozilla/mozilla-release
set TOFINO ~/Work/Mozilla/tofino
alias mozdev "cd $MOZDEV"
alias fxteam "cd $FXTEAM"
alias m-gum "cd $GUM"
alias m-inbound "cd $M_INBOUND"
alias m-central "cd $M_CENTRAL"
alias m-aurora "cd $M_AURORA"
alias m-beta "cd $M_BETA"
alias m-release "cd $M_RELEASE"
alias tofino "cd $TOFINO"
function fxbuild --description "Build firefox from source"
set -gx MOZCONFIG $MOZCONFIG
set -gx CCACHE_DIR $CCACHE_DIR
if [ (uname) = "Darwin" ]
say -v V "Build started."
end
./mach build $argv
if [ (uname) = "Darwin" ]
say -v V "Build finished."
end
end
function fxrun --description "Open firefox from the obj/dist directory using a specified profile"
if [ (count $argv) = 0 ]
fxrun development
return
end
set -gx MOZ_DISABLE_SAFE_MODE_KEY 1
set -gx MOZ_QUIET 1
./mach run -P $argv
end
function fxtry --description "Pushes to try"
if [ (: hgsq) ]
hgs
return
end
if [ (count $argv) = 0 ]
return
end
set build "-b "
set platf "-p "
set tests "-u "
set talos "-t "
set rebuild ""
if contains "debug" $argv
set build $build"d"
else if contains "opt" $argv
set build $build"o"
else
set build $build"do"
end
if contains "all-platforms" $argv
set platf $platf"all"
else
if contains "linux" $argv
set platf $platf"linux,linux64,linux64-asan,"
end
if contains "mac" $argv
set platf $platf"macosx64,"
end
if contains "osx" $argv
set platf $platf"macosx64,"
end
if contains "win" $argv
set platf $platf"win32,win64,"
end
end
if contains "all-tests" $argv
set tests $tests"all";
else if contains "none" $argv
set tests $tests"none";
else
if contains "m" $argv
set tests $tests"mochitests,";
end
if contains "bc" $argv
set tests $tests"mochitest-bc,";
end
if contains "dt" $argv
set tests $tests"mochitest-dt,mochitest-e10s-devtools-chrome,";
end
if contains "oth" $argv
set tests $tests"mochitest-o,";
end
if contains "xpc" $argv
set tests $tests"xpcshell,";
end
end
set tests (@ $tests | sed '$s/.$//')
if contains "talos" $argv
set talos $talos"all"
else
set talos $talos"none"
end
if contains "rebuild" $argv
set rebuild "--rebuild 20";
end
qnew _ -m "try: $build $platf $tests $talos $rebuild"
qser
if [ (uname) = "Darwin" ]
say "Pushing to try."
end
hgpf $HG_TRY
if [ (uname) = "Darwin" ]
say "Done"
end
qpo
qrm _
end
# Shell prompt
set -g RESPONSIVE_PROMPT_COLUMNS 110
function __prompt_set_self_addr_wdir
if not set -q __self
set -g __self (whoami)
set -g __addr (ifconfig | grep "inet " | grep -v "127.0.0.1" | head -n 1 | tr -d "addr:" | awk '{print $2}')
set -g __self_len (@ $__self | wc -m)
set -g __addr_len (@ $__addr | wc -m)
end
if [ $COLUMNS -gt $RESPONSIVE_PROMPT_COLUMNS ]
set -g __self_addr_wdir $_brown $__self $_normal " at " $_green $__addr $_normal " in " $_bold $_green (prompt_pwd) $_normal
else
set -g __self_addr_wdir $_bold $_green (prompt_pwd) $_normal
end
end
function __prompt_set_hg_git
if not set -q __has_hg
set -g __has_hg (which hg)
end
if not set -q __has_git
set -g __has_git (which git)
end
if [ $__has_hg ]
set -g __is_hg_wdir (: hg root)
if [ $__is_hg_wdir ]
set hg_info (hg parent --template "{branch},{node},{tags}")
set hg_qseries (hg qseries --verbose)
set hg_branch (@ $hg_info | cut -d "," -f 1)
set hg_tip_cset (@ $hg_info | cut -d "," -f 2 | cut -c 1-12)
set hg_tip_tags (@ $hg_info | cut -d "," -f 3)
set -g __hg_tip_patch (@ $hg_tip_tags | sed 's/qbase//' | sed 's/qtip//' | sed 's/tip//' | @% "%s ")
set hg_qa (@ $hg_qseries | grep -o " A " | wc -l | tr -d " ")
set hg_mq (@ $hg_qseries | grep -o " [AU] " | wc -l | tr -d " ")
if [ $COLUMNS -gt $RESPONSIVE_PROMPT_COLUMNS ]
set -g __hg_repo_info $_normal "[ " $_magenta $_black_bkg "hg" $_normal_bkg " on " $_blue $hg_branch " " $_red $hg_tip_cset " " $_cyan $hg_qa/$hg_mq $_normal " ]"
else
set -g __hg_repo_info $_normal "[ " $_magenta $_black_bkg "hg" $_normal_bkg " on " $_red $hg_tip_cset " " $_cyan $hg_qa/$hg_mq $_normal " ]"
end
end
end
if [ $__has_git ]
set -g __is_git_wdir (: git rev-parse --show-toplevel)
if [ $__is_git_wdir ]
set -g __git_branch (git symbolic-ref --quiet HEAD | cut -d "/" -f 3)
set -g __git_tip_cset (git rev-parse --short HEAD)
if not [ $__git_branch ]
set -g __git_is_detached "(detached)"
else
set -e __git_is_detached
end
if [ $COLUMNS -gt $RESPONSIVE_PROMPT_COLUMNS ]
set -g __git_repo_info $_normal "[ " $_magenta $_black_bkg "git" $_normal_bkg " on " $_blue $__git_branch " " $_red $__git_tip_cset $_normal " ]"
else
set -g __git_repo_info $_normal "[ " $_magenta $_black_bkg "git" $_normal_bkg " on " $_red $__git_tip_cset $_normal " ]"
end
end
end
end
function fish_prompt
__prompt_set_self_addr_wdir
__prompt_set_hg_git
if [ $__is_hg_wdir ]
if [ (: hgsq) ]
@ "[ " $_cyan $__hg_tip_patch $_red $_bold "✘" $_normal " ] " $_blue $_bold "λ " $_normal
else
@ "[ " $_cyan $__hg_tip_patch $_green $_bold "✔" $_normal " ] " $_blue $_bold "λ " $_normal
end
else if [ $__is_git_wdir ]
set git_status (git status --porcelain)
if [ $__git_is_detached ]
set untrk "[ " $_cyan $__git_tip_cset $_yellow " detached " $_yellow $_bold "?" $_normal " ] " $_blue $_bold "λ " $_normal
set dirty "[ " $_cyan $__git_tip_cset $_yellow " detached " $_red $_bold "✘" $_normal " ] " $_blue $_bold "λ " $_normal
set clean "[ " $_cyan $__git_tip_cset $_yellow " detached " $_green $_bold "✔" $_normal " ] " $_blue $_bold "λ " $_normal
else
set untrk "[ " $_cyan $__git_branch " " $_yellow $_bold "?" $_normal " ] " $_blue $_bold "λ " $_normal
set dirty "[ " $_cyan $__git_branch " " $_red $_bold "✘" $_normal " ] " $_blue $_bold "λ " $_normal
set clean "[ " $_cyan $__git_branch " " $_green $_bold "✔" $_normal " ] " $_blue $_bold "λ " $_normal
end
if [ (@ $git_status | grep -c "?? ") -gt 0 ]
@ $untrk
else if [ (@ $git_status | grep -c " M ") -gt 0 ]
@ $dirty
else if [ (@ $git_status | grep -c "MM ") -gt 0 ]
@ $dirty
else if [ (@ $git_status | grep -c "A ") -gt 0 ]
@ $dirty
else if [ (@ $git_status | grep -c "AM") -gt 0 ]
@ $dirty
else if [ (@ $git_status | grep -c "D ") -gt 0 ]
@ $dirty
else
@ $clean
end
else
@ $_blue "λ " $_normal
end
end
function fish_right_prompt
@ $__self_addr_wdir
if [ $__is_hg_wdir ]
@ " " $__hg_repo_info
end
if [ $__is_git_wdir ]
@ " " $__git_repo_info
end
end
test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment