Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Last active January 26, 2018 20:03
Show Gist options
  • Save nicinabox/09b4ccf29d1952e741bd26d1cd1d9b39 to your computer and use it in GitHub Desktop.
Save nicinabox/09b4ccf29d1952e741bd26d1cd1d9b39 to your computer and use it in GitHub Desktop.

Revisions

  1. nicinabox revised this gist Jan 26, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions terminal notes.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    ![screen shot 2018-01-26 at 13 59 43](https://user-images.githubusercontent.com/246280/35458358-a0cb15f0-02a1-11e8-85ba-433068e44bd8.png)

    ## iTerm

    I can't remember exactly why I started using this over the built in Terminal, but it's very customizable and feature rich.
  2. nicinabox renamed this gist Jan 26, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. nicinabox created this gist Jan 26, 2018.
    69 changes: 69 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    ## iTerm

    I can't remember exactly why I started using this over the built in Terminal, but it's very customizable and feature rich.

    ## zsh

    Originally I switched to zsh to try something different from bash. Now I rely on features like [hook functions](http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions) and [syntax highlighting](https://github.com/zsh-users/zsh-syntax-highlighting).

    I use [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) with [pure-prompt](https://github.com/sindresorhus/pure).

    ### zsh hooks

    One that I've come to rely on a lot is automatically sourcing a `.env` file in the current directory. This is for setting environment variables and secrets specific to a project and also keep them out of git.

    ```
    function source_env() {
    if [[ -f .env ]]; then
    source .env
    fi
    }

    add-zsh-hook chpwd source_env
    ```

    While in Austin I did a similar one for virtualenv. It looks for a `.venv` file including the name of the thing you want to work on and calls `workon` and `deactivate` automatically when you move in and out of directories that have that defined.

    ## tmux

    tmux does window and pane management within a single terminal window (it's a Terminal MUltipleXer). It takes some practice move around and get configured in a useful way, but it's incredibly powerful and has become absolutely essential in my workflow. Restoring a detached session has saved me many times after accidentally closing a terminal tab.

    ## dotfiles

    As you start to build up state with a bunch of config files it's helpful to have them in a place you can carry them around. I keep mine in git and symlink the source dotfiles to their respective places (home directory usually).

    This way I can tweak gitconfig/tmux/vim/zshrc and have it available and up to date across machines.

    ## git aliases

    Some common ones I use daily or frequently:

    st = status
    ci = commit
    br = branch
    co = checkout
    cp = cherry-pick

    Pretty logging:

    lg = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr %an)%Creset' --abbrev-commit --date=relative

    Logging with graph:

    lol = log --graph --decorate --pretty=oneline --abbrev-commit

    Latest tag:

    latest-tag = describe --tags --abbrev=0

    Logging after the latest tag (latest tag to HEAD)

    lg-latest = "!f() { \
    git log `git latest-tag`..HEAD --format='%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s' --date=relative; \
    }; f"

    Cleanup locally merged branches

    br-clean = "!f() { \
    git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs git branch -d; \
    }; f"