Skip to content

Instantly share code, notes, and snippets.

@dewaka
Last active September 16, 2019 12:41
Show Gist options
  • Save dewaka/6d0758af89fd0840ee2781818ae48532 to your computer and use it in GitHub Desktop.
Save dewaka/6d0758af89fd0840ee2781818ae48532 to your computer and use it in GitHub Desktop.
# Config to fix z.lua
# See - https://github.com/skywind3000/z.lua/issues/47
set -gx _ZL_CD cd
alias t "tmux"
# alias e "edit_files"
alias e "$EDITOR (fzf -m --reverse --height 40%)"
alias o "exo-open 2>/dev/null"
alias ec "emacsclient -nw"
alias vo "vim (fzf -m --reverse --height 40%)"
alias em "emacsclient -tn"
alias eo "emacsclient -tn (fzf -m --reverse --height 40%)"
alias ki "kinit ccolomb"
alias updt "sudo apt update; and sudo apt upgrade"
alias rt "pkill -USR1 redshift"
alias start-docker "sudo snap enable docker"
alias stop-docker "sudo snap disable docker"
alias custom-keys "xmodmap ~/.Xmodmap.Custom"
alias kerb "kinit ccolomb"
alias trash "gio trash -f"
alias trash-empty "gio trash --empty"
alias hex "wxHexEditor 2>/dev/null"
# To clean up the trash folder of Vifm
function vf-cleanup
for tfile in ~/.local/share/vifm/Trash/*
trash $tfile
end
end
# Syntax highlighting cat
alias c "highlight -O ansi --force"
# Python stuff
alias source-conda "source $HOME/Apps/miniconda3/etc/fish/conf.d/conda.fish"
# Update nix-channels
# Upgrade all installed packages
# Collect garbage
alias nix-updt "nix-channel --update; and nix-env -u; and nix-collect-garbage"
# z.lua aliases
alias zz "z -c" # restrict matches to subdirs of $PWD
alias zi "z -i" # cd with interactive selection
alias zf "z -I" # use fzf to select in multiple matches
alias zb "z -b"
alias j "z -I -t ."
alias d "z -e" # just echo the matching directory without cd-ing
# Useful directories
set -x Dropbox $HOME/Dropbox
set -x Library $Dropbox/Library
set -x Books $Library/Books
set -x Projects $Dropbox/Projects
set -x Documents $Dropbox/Documents
set -x Notes $Documents/Notes
set -x WorkNotes $Documents/Notes/work/2019
function nix-search -d "Nix package search"
nix-env -qaP ".*$argv"
end
# I followed function __fzf_alt_c to define the one below
# function zd --argument-names 'name'
# set -l zd_command "command fasd -Rdl $name 2> /dev/null"
# fish -c "$zd_command" | fzf -1 -0 --no-sort -m | read -la select
# # fish -c "$zd_command" | __fzfcmd -1 -0 --no-sort -m | read -la select
# if test ! (count $select) -eq 0
# cd "$select"
# end
# end
# from - https://github.com/JDevlieghere/dotfiles/blob/master/.config/fish/functions/mkd.fish
function mkcd -d "Create a new directory and enter it"
mkdir -p $argv; and cd $argv
end
function notes --description "select org-mode note files"
set ntype $argv[1]
if test -n "$ntype"
switch $ntype
# Work notes
case w work
set work_year $argv[2]
if test -n "$work_year"
switch $work_year
case 19 2019
find ~/Dropbox/Documents/Notes/work/2019 -type f -name '*.org' | fzf -m
case 18 2018
find ~/Dropbox/Documents/Notes/work/2018 -type f -name '*.org' | fzf -m
case 17 2017
find ~/Dropbox/Documents/Notes/work/2017 -type f -name '*.org' | fzf -m
case 16 2016
find ~/Dropbox/Documents/Notes/work/2016 -type f -name '*.org' | fzf -m
case 15 2015
find ~/Dropbox/Documents/Notes/work/2015 -type f -name '*.org' | fzf -m
case '*'
find ~/Dropbox/Documents/Notes/work -type f -name '*.org' | fzf -m
end
else
find ~/Dropbox/Documents/Notes/work -type f -name '*.org' | fzf -m
end
# Work JIRA notes
case j jira
set work_year $argv[2]
if test -n "$work_year"
switch $work_year
case 19 2019
find ~/Dropbox/Documents/Notes/work/2019 -type f -name 'JIRA*.org' | fzf -m
case 18 2018
find ~/Dropbox/Documents/Notes/work/2018 -type f -name 'JIRA*.org' | fzf -m
case 17 2017
find ~/Dropbox/Documents/Notes/work/2017 -type f -name 'JIRA*.org' | fzf -m
case 16 2016
find ~/Dropbox/Documents/Notes/work/2016 -type f -name 'JIRA*.org' | fzf -m
case 15 2015
find ~/Dropbox/Documents/Notes/work/2015 -type f -name 'JIRA*.org' | fzf -m
case '*'
find ~/Dropbox/Documents/Notes/work -type f -name 'JIRA*.org' | fzf -m
end
else
find ~/Dropbox/Documents/Notes/work -type f -name 'JIRA*.org' | fzf -m
end
# Daily notes
case d daily
find ~/Dropbox/Documents/Notes/{2019,2018,2017,2016,2015} -type f -name '*.org' | fzf -m
case 19 2019
find ~/Dropbox/Documents/Notes/2019 -type f -name '*.org' | fzf -m
case 18 2018
find ~/Dropbox/Documents/Notes/2018 -type f -name '*.org' | fzf -m
case 17 2017
find ~/Dropbox/Documents/Notes/2017 -type f -name '*.org' | fzf -m
case 16 2016
find ~/Dropbox/Documents/Notes/2016 -type f -name '*.org' | fzf -m
case 15 2015
find ~/Dropbox/Documents/Notes/2015 -type f -name '*.org' | fzf -m
case '*'
find ~/Dropbox/Documents/Notes -type f -name '*.org' | fzf -m
end
else
find ~/Dropbox/Documents/Notes -type f -name '*.org' | fzf -m
end
end
# Mnemonic - Run in Directory
function rd --description "run given commands in directory without changing current directory"
set dir $argv[1]
set --erase argv[1]
if test -n "$dir"
# Run in a sub shell so that we do not change directory stack
fish -c "
pushd $dir
eval $argv
"
end
end
# function edit_files --description "edit, given files or fzf selected files in default editor"
# set files $argv[1..-1]
# if test -n "$files"
# $EDITOR "$files"
# else
# eval "$EDITOR (fzf -m --reverse --height 40%)"
# end
# end
# Git stuff
function fb -d "Fuzzy-find and checkout a local branch"
git branch -vv | awk '{print $1}' | string trim | fzf | xargs git checkout
end
function fco -d "Fuzzy-find and checkout a branch"
git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result"
end
function fcoc -d "Fuzzy-find and checkout a commit"
git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result"
end
function ofd -d "Open directory of the file"
exo-open (dirname "$argv") 2>/dev/null
end
function track -d "Music track info"
printf "%s - %s\n" (playerctl metadata artist) (playerctl metadata title)
end
### Abbreviations ###
# git
abbr -a -g g git
abbr -a -g gc git checkout
abbr -a -g gs git status
abbr -a -g gst git stash
abbr -a -g gsl git stash list
abbr -a -g gsp git stash pop
abbr -a -g ga git add
abbr -a -g gf git fetch
abbr -a -g gp git pull
abbr -a -g gps git push
abbr -a -g gm git merge
abbr -a -g gd git diff
abbr -a -g gco git commit
abbr -a -g gca git commit -a
# vim
abbr -a -g gv gvim
abbr -a -g v vim
# vifm
abbr -a -g vf vifm
abbr -a -g vd vifm .
# python
#
abbr -a -g pe pipenv
abbr -a -g pes pipenv shell
abbr -a -g pei pipenv install
abbr -a -g pec pipenv clean
abbr -a -g peu pipenv uninstall
abbr -a -g peup pipenv update
abbr -a -g pel pipenv lock
abbr -a -g jn jupyter notebook
# maven
abbr -a -g m mvn
abbr -a -g mc mvn compile
abbr -a -g mcl mvn clean
abbr -a -g mt mvn test
abbr -a -g mts mvn test -Dsuites=
abbr -a -g mp mvn package -DskipTests=true
abbr -a -g msc mvn scala:console
abbr -a -g mj mvn exec:java
# nix
abbr -a -g n nix-env
abbr -a -g ns nix-search
abbr -a -g ni nix-env -i
abbr -a -g nu nix-updt
abbr -a -g ngc nix-collect-garbage
# npm
abbr -a -g nps npm start
abbr -a -g npi npm install
# clojure
abbr -a -g lc lein compile
abbr -a -g lt lein test
abbr -a -g lcl lein clean
abbr -a -g lch lein check
# ripgrep (rg)
abbr -a -g rgf rg --files-with-matches
# Fish history merge
abbr -a -g hr history --merge
# pgrep and pkill
abbr -a -g pg pgrep
abbr -a -g pk pkill
# htop
abbr -a -g ht htop
# Docker
abbr -a -g ds docker ps -a
abbr -a -g dq docker ps -aq
abbr -a -g di docker images
abbr -a -g dco docker-compose
abbr -a -g dl docker logs
abbr -a -g dst docker start
abbr -a -g dsp docker stop
abbr -a -g drm docker rm
# Work task aliases
set -x Code $HOME/Code
set -x Inno $Code/inno
set -x Wrangler $Inno/data-wrangler
set -x WranglerFE $Inno/data-wrangler-frontend
alias start-wrangler "rd $Wrangler mvn exec:java"
alias start-wrangler-fe "rd $WranglerFE npm start"
function custom_bindings
# open vifm for Ctrl+O
bind \co vifm
end
# set -g fish_key_bindings custom_bindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment