Ben's Blog

Useful bash / zsh Profile Additions

Some functions I found useful to add to my bash and zsh profile.

May 27, 2020

Update 2020-01-11 - I switched a lot of this stuff over to using DotBot after seeing this repo. You can see my dotfile repo here - it should work in whatever setup you’re using, although some stuff might be specific to my own setup.

These are a bunch of additions I like to add to my local profile which I’ve found make me more productive. As best I could I tried to make it so that the instructions can be followed pretty mindlessly (mostly because I sometimes have to copy-paste stuff into a new environment).

Git Aliases

Some useful Git aliases

Give a nice-looking commit tree

This is similar to the hg sl command we use at Facebook.

git config --global 'log --graph --decorate --oneline'


Usage: more friendly ls

I guess this is pretty standard but the ls command has some useful modifiers.

alias ll='ls -ahl'


Usage: today gives the current date and now gives the current time

alias today='date +"%Y-%m-%d"'
alias now='date +"%T"'


$ echo $(today)
$ echo $(now)

Google Drive

Usage: gdrive <fid> <fpath> where <fid> is the Google Drive file identifier and <fpath> is the output path

function gdrive {
  if [[ $# -ne 2 ]]; then
    echo "Usage: gdrive <fid> <fpath>"
    exit 1
  O=$(wget \
    --quiet \
    --save-cookies /tmp/cookies.txt \
    --keep-session-cookies \
    --no-check-certificate \
    "${FILEID}" -O- | \
    sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
  wget \
    --load-cookies /tmp/cookies.txt \
    "${O}&id=${FILEID}" \
  rm -rf /tmp/cookies.txt


tmux is a must for remote development. Here are some of my personal add-ons to make it work a bit better.

List Open Sessions

Usage: List open sessions on a machine on startup

if [[ -n $TMUX ]]; then
  echo -e "\033[1;31m----- TMUX session: $(tmux display-message -p '#S') -----\033[0m"
elif [[ ! -n $TMUX ]] && [[ $(tmux ls 2> /dev/null) ]]; then
  echo -e "\033[1;31m----- Open tmux sessions -----\033[0m"
  tmux ls
  echo -e "\033[1;31m------------------------------\033[0m"

Attach to Named Session in Control Mode

Usage: tmuxc <session>, can use tab completion to get the named session

Using named sessions is very important for organizing multiple projects. Otherwise I found it really easy to lose track of where stuff is.

alias tmuxc='tmux -CC a -t'

### Provides tab completion for the tmuxc command.
  local cur opts
  opts="$(tmux list-sessions -F '#S' | paste -sd ' ')"
  COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  return 0
complete -F _tmuxc_complete tmuxc


Usage: Shorthand and tab completion for activating a Conda environment

alias cenv='conda activate'

  local cur opts
  opts="$(ls -1 ${HOME}/.conda/envs/ | paste -sd ' ')"
  COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  return 0
complete -F _conda_complete 'cenv'

uBlock Origin

This is more of a productivity tip. I have a blocklist that blocks the endless scrolling parts of some social media sites without blocking potentially informative posts.

Click here to subscribe