Skip to content

Instantly share code, notes, and snippets.

@aral
Last active April 28, 2022 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aral/6fbffb5f2d5194986f45bc2169d123c7 to your computer and use it in GitHub Desktop.
Save aral/6fbffb5f2d5194986f45bc2169d123c7 to your computer and use it in GitHub Desktop.
My fish shell configuration files

Instructions

Install plugins using Fisher.

Tide prompt customisation

Replace .config/fish/functions/_tide_item_git.fish with the file here to use words instead of symbols to describe git repository state.

function _tide_item_git
# Branch or SHA
set -l branch (git branch --show-current 2>/dev/null) || return
# --quiet=don't complain if there are no commits
git rev-parse --quiet --git-dir --is-inside-git-dir --short HEAD |
read --local --line gitDir isInsideGitDir location
test -n "$branch" && set location $branch # location is SHA if branch is empty
# Operation
set -l operation
set -l step
set -l totalSteps
if test -d $gitDir/rebase-merge
read step <$gitDir/rebase-merge/msgnum
read totalSteps <$gitDir/rebase-merge/end
if test -f $gitDir/rebase-merge/interactive
set operation rebase-i
else
set operation rebase-m
end
else if test -d $gitDir/rebase-apply
read step <$gitDir/rebase-apply/next
read totalSteps <$gitDir/rebase-apply/last
if test -f $gitDir/rebase-apply/rebasing
set operation rebase
else if test -f $gitDir/rebase-apply/applying
set operation am
else
set operation am/rebase
end
else if test -f $gitDir/MERGE_HEAD
set operation merge
else if test -f $gitDir/CHERRY_PICK_HEAD
set operation cherry-pick
else if test -f $gitDir/REVERT_HEAD
set operation revert
else if test -f $gitDir/BISECT_LOG
set operation bisect
end
# Upstream behind/ahead
# Suppress errors in case there is no upstream
git rev-list --count --left-right @{upstream}...HEAD 2>/dev/null |
read --local --delimiter=\t upstreamBehind upstreamAhead
test "$upstreamBehind" = 0 && set -e upstreamBehind
test "$upstreamAhead" = 0 && set -e upstreamAhead
# Git status/stash
test "$isInsideGitDir" = true && set -l gitSetDirOption -C $gitDir/..
# Suppress errors in case we are in a bare repo
set -l gitInfo (git $gitSetDirOption --no-optional-locks status --porcelain 2>/dev/null)
set -l stash (git $gitSetDirOption stash list 2>/dev/null | count) || set -e stash
set -l conflicted (string match --regex '^UU' $gitInfo | count) || set -e conflicted
set -l staged (string match --regex '^[ADMR].' $gitInfo | count) || set -e staged
set -l dirty (string match --regex '^.[AMR]' $gitInfo | count) || set -e dirty
set -l deleted (string match --regex '^.D' $gitInfo | count) || set -e deleted
set -l untracked (string match --regex '^\?\?' $gitInfo | count) || set -e untracked
# Print the information
printf '%s' \
'❨git❩  '(set_color $tide_git_branch_color) $location \
(set_color $tide_git_operation_color) ' '$operation ' '$step/$totalSteps \
(set_color $tide_git_upstream_color) ' '$upstreamBehind' commit(s) behind remote' ' '$upstreamAhead' commit(s) ahead of remote' \
(set_color $tide_git_stash_color) ' '$stash' stashed' \
(set_color $tide_git_conflicted_color) ' '$conflicted' conflicted' \
(set_color $tide_git_staged_color) ' '$staged' staged' \
(set_color $tide_git_dirty_color) ' '$dirty' dirty' \
(set_color $tide_git_dirty_color) ' '$deleted' deleted' \
(set_color $tide_git_untracked_color) ' '$untracked' untracked'
end
if status is-interactive
#
# Aliases
#
# VSCodium
alias code '/usr/bin/codium'
#
# Abbreviations
#
# Copy and paste to the clipboard by piping to these commands.
# (Inspired by the default behaviour in macOS.)
abbr --add --global pbcopy 'xsel --clipboard --input'
abbr --add --global pbpaste 'xsel --clipboard --output'
# Open files in their associated apps from Terminal.
abbr --add --global open 'xdg-open &>/dev/null '
# Git aliases to make git a little bit more humane for everyday use.
abbr --add --global git-log 'git log --graph --decorate --pretty=oneline --abbrev-commit'
abbr --add --global git-log-dates 'git log --graph --decorate --pretty=format:"%h [%cr] %s'
abbr --add --global git-tag 'git tag -n'
abbr --add --global git-undo-last-commit 'git reset HEAD~'
# Aliases for getting system and app information.
abbr --add --global system-information 'neofetch'
abbr --add --global disk-usage 'dust'
abbr --add --global which-kernel 'apt-cache policy linux-generic'
abbr --add --global node-v8-version 'node -p process.versions.v8'
# Make rm a little safer (have it prompt once when deleting more than
# three files or when deleting recursively).
abbr --add --global rm 'rm -I'
# A nicer ls that also shows the git status of files
abbr --add --global l 'exa -lh --git --all'
# Use broot instead of ls (for more complicated interactive views)
abbr --add --global ls 'br'
# A nicer ls that also shows the git status of files (but not hidden files)
abbr --add --global ll 'exa -lh --git'
# Same nicer ls but in tree view.
abbr --add --global lt 'exa -lh --git --all --tree'
# lc = line count
abbr --add --global lc 'wc -l'
# Find out what’s running on port X
abbr --add --global port 'lsof -i'
# Better find
abbr --add --global find 'fd'
# Better ps
abbr --add --global ps 'procs'
# npm
abbr --add --global t 'npm -s test'
abbr --add --global td 'npm -s test-debug'
abbr --add --global coverage 'npm -s coverage'
abbr --add --global coverage-debug 'npm -s coverage-debug'
abbr --add --global package-details 'npm --dry-run publish'
# Package.json validator
abbr --add --global validate-package.json 'pjv package.json'
# Use ripgrep instead of grep
abbr --add --global grep 'rg'
end
jorgebucaran/fisher
small-tech/gills
jorgebucaran/nvm.fish
nickeb96/puffer-fish
jethrokuan/z
jorgebucaran/autopair.fish
dracula/fish
aral/tide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment