Fish & Gits

I’ve been using the Fish shell for a while, and it’s really gotten to the point where I miss it when I can’t use it :)

To share with folks, here are some of my Fish configurations and Git configs that make my life as a Blender developer easier.

This post was made possible by the Blender Development Fund.

Fish Config

These I store in ~/.config/fish/conf.d/aliases.fish:

set BLENDER_BUILD_ROOT  /home/sybren/workspace/blender-git

function cdlibs -d "CD to Blender libs directory"
    cd $BLENDER_BUILD_ROOT/lib
end

function cddeps -d "CD to Blender deps directory"
    cd $BLENDER_BUILD_ROOT/build_deps/deps
end

function cdbuild -d "CD to Blender build directory"
    cd $BLENDER_BUILD_ROOT/build_linux
end

function cdsrc -d "CD to Blender source directory"
    cd $BLENDER_BUILD_ROOT/blender
end

function cdtracker -d "CD to Blender bug tracker directory"
    cd $BLENDER_BUILD_ROOT/tracker
end

function bb -d "Build Blender, release mode"
    nice -n 1 ninja -C $BLENDER_BUILD_ROOT/build_linux/ $argv
end

function bbb -d "Build Blender and run with last file"
    bb && blender --open-last $argv
end

function bbd -d "Build Blender, debug mode"
    nice -n 1 ninja -C $BLENDER_BUILD_ROOT/build_debug/ $argv
end

function bbbd -d "Build Blender in Debug mode and run with last file"
    bbd && blenderdebug --open-last $argv
end

function bbt -d "Build Blender, Clang-Tidy mode"
    nice -n 1 ninja -C $BLENDER_BUILD_ROOT/build_tidy/ $argv
end

function bbr -d "Build Blender, release branch"
    nice -n 1 ninja -C $BLENDER_BUILD_ROOT/build_release/ $argv
end

function cdb
    set BLENDVER (blender --version | grep '^Blender' | cut -d' ' -f2 | sed 's/\\([0-9]\\+\\.[0-9]\\+\\).*/\\1/')
    echo "Blender version: $BLENDVER"
    cd ~/.config/blender/$BLENDVER
end

function git_rebase_onto_master
    read -P "Rebase onto master? ENTER for yes, CTRL+C for no."
    git rebase master; and git submodule foreach git pull --rebase origin master
end

function arcpull -d "Refresh and reapply the current patch from Phabricator"
    set BRANCH (git branch --show-current 2>/dev/null)
    if [ -z "$BRANCH" ];
        echo "Not on a Git repo"
        return 42
    end

    set PATCHNUM (string replace arcpatch-D '' $BRANCH)
    if [ $BRANCH = $PATCHNUM ];
        echo "Current branch $BRANCH is not an arcpatch branch" >&2
        return 47
    end
    echo "Current branch $BRANCH is for patch $PATCHNUM"

    git checkout master
    git branch -D $BRANCH
    arc patch D$PATCHNUM
    printf "\033[95mBranch $BRANCH is ready for use\033[0m\n"
    git_rebase_onto_master
end

function arcpatch -a PATCHNAME -d "Apply a patch from Phabricator"
    if test -z "$PATCHNAME";
        echo "Usage: arcpatch D1234" >&2
        return 47
    end

    set BRANCH arcpatch-$PATCHNAME

    set CURBRANCH (git branch --show-current 2>/dev/null)
    if test "$CURBRANCH" != "master";
        git checkout master
    end

    if git branch | grep -q $BRANCH;
        printf "\033[95mBranch $BRANCH exists, going to refresh it\033[0m\n"
        git branch -D $BRANCH
    else
        printf "\033[96mBranch $BRANCH does not exist\033[0m\n"
    end
    arc patch $PATCHNAME
    printf "\033[95mBranch $BRANCH is ready for use\033[0m\n"
    git_rebase_onto_master
end

function arcprune -d "Delete all arcpatch-Dxxxx branches"
    set BRANCHES (string trim (git branch | grep arcpatch-D))
    if test -z "$BRANCHES";
        echo "No arc branches to prune"
        return 0
    end
    git branch -D $BRANCHES
end

function svnadd -a SUBDIR -d "Add new files and remove deleted files"
  # This is the Fish way of doing `SVN_STATUS=$(<svn status $SUBDIR)`
  begin; set -l IFS; set SVN_STATUS (svn status $SUBDIR); end

  echo "$SVN_STATUS" | grep '^\? ' | sed 's/^.//' | xargs --no-run-if-empty -n 1 svn add
  echo "$SVN_STATUS" | grep '^\! ' | sed 's/^.//' | xargs --no-run-if-empty -n 1 svn rm
end

function gswitch -a BRANCH -d "Git: switch to branch and also update submodules"
    if test -z "$BRANCH";
        echo "No branch given"
        return 47
    end

    git switch $BRANCH
    git submodule update --remote
    git submodule foreach 'git checkout $(git describe --all | cut -d/ -f2)'
end

alias l='ls -F --color=auto'
alias ll='l -lh'
alias df='df -h'
alias du='du -h'
alias grep='grep --color'
alias json_pp="python3 -c 'import json, sys; print(json.dumps(json.load(sys.stdin), sort_keys=True, indent=4))'"
alias trimlong="sed 's/\(.\{120\}\).*/\1…/'"
alias ffprobe-json="ffprobe -v error -hide_banner -print_format json -show_streams -show_format"
alias dot2png="dot -Tpng -O"
alias abccat="abcls -a -m -l -r -t"
alias cdp="cd (pwd -P)"
alias bcode="code ~/workspace/blender-git/blender.code-workspace"

Git Config

My Git configuration (~/.gitconfig) also has some nice aliases & other options:

[color]
    ui = auto
[pull]
    rebase = true
[push]
    default = simple
[alias]
    co = "checkout"
    cp = "cherry-pick"
    ff = "merge --ff-only"
    mt = "mergetool"
    up = "checkout @~1"
    st = "status --ignore-submodules=none"
    car = "commit --amend --reset-author"
    rbi = "rebase -i"
    rbc = "rebase --continue"
    rba = "rebase --abort"
    tpush = "!git push && git push --tags"
    out = "log @{u}.. --pretty=oneline"
    head = "show HEAD"
    unstash = "stash pop"
    authors = "!f() { git log --since 'now - 1 year' \"$@\" | grep ^Author | sed 's/Author: //' | sed 's/<.*>//' | sort -f | uniq -ci | sort -nr | nl -s '' | sort -nr; } ; f"
    glog = "log --all --graph --abbrev-commit --decorate --date=short --format=format:'%C(bold blue)%h%C(reset) %C(green)(%ad)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(dim magenta)%d%C(reset)'"
    onelog = "log --abbrev-commit --decorate --date=short --format=format:'%C(bold blue)%h%C(reset) %C(green)(%ad)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(dim magenta)%d%C(reset)'"
    ver = "log --oneline -n 1 --no-abbrev"
[diff]
    tool = kdiff3
    guitool = kdiff3
[merge]
    tool = kdiff3
    guitool = kdiff3
  	renamelimit = 4096
[core]
    excludesfile = /home/sybren/.configfiles/gitignore_global
[gui]
    gcwarning = false
    encoding = utf-8
[rerere]
  	enabled = true
[gc]
  	rerereUnresolved = 365
  	rerereResolved = 365
dr. Sybren A. Stüvel
dr. Sybren A. Stüvel
Open Source software developer, photographer, drummer, and electronics tinkerer

Related