Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

141–150 of 288 posts

Re: Ask HN: Best things in your bash_profile/aliases?

#141

Here is my lot # setting common options alias cp='cp -iv' alias mv='mv -iv' alias rmdir='rmdir -v' alias ln='ln -v' alias ls='ls --color=auto --human-readable --group-directories-first --classify' alias grep='grep --color=auto' # shortcuts alias e=vim alias music=ncmpcpp alias g='git status' alias gp='git push' # show pretty git diff alias gitdiff='git difftool -y -x "colordiff -y -W $COLUMNS" | less -R' # go to root…

livestreamer is dead, long live streamlink

Re: Ask HN: Best things in your bash_profile/aliases?

#143
post #45

I lifted most of this from the guy mentioned in the hn post in the comments below. I don't know what shell/platform he used, but it didn't work from twitter so I tweaked it to work on the linux boxes I typically see. It creates a different history file from each shell session. Most of my shell history goes back about 3 years now. The downside is you can't up arrow or crtl R except for your current history, but you ca…

HISTIGNORE is really cool

Re: Ask HN: Best things in your bash_profile/aliases?

#144
This one I use daily without thinking about it - it shares my bash history between screens and sessions on a given machine and extends it (grabbed from some corner of the internet):

    # shares history between tabs with prompt_command
    HISTSIZE=9000
    HISTFILESIZE=$HISTSIZE
    HISTCONTROL=ignorespace:ignoredups

    _bash_history_sync() {
      builtin history -a         #1 appends command to histfile
      HISTFILESIZE=$HISTSIZE     #2 sets max size
      builtin history -c         #3 clears current session history
      builtin history -r         #4 reads the updated histfile and makes that the current history
    }

    history() {                  #5 overrides build in history to sync it before display
      _bash_history_sync
      builtin history "$@"
    }

    PROMPT_COMMAND=_bash_history_sync
Sometimes I forget the name of git branches I've worked on lately. This displays them with dates, most recent at the bottom:

    git_branch_dates() {
      git for-each-ref --sort=authordate --format '%(authordate:iso) %(align:left,25)%(refname:short)%(end) %(subject)' refs/heads
    }
Because I hate typing:

    # for rails migrations and keeping test updated
    alias migrate="rake db:migrate && RAILS_ENV=test rake db:migrate"
Something I should use more to track things I've done lately - this opens up vim at the end of a file in your home dir called did.txt, appends the date and puts cursor at the last line:

    # didfile setup
    alias did="vim +'normal Go' +'r!date' ~/did.txt"
Because sometimes you want to sudo an alias:

    # trailing space in value expands aliases that come after, see: http://www.linuxcommand.org/lc3_man_pages/aliash.html
    alias sudo='sudo '
And displaying the git branch in the prompt:

    # this gets the git branch to display when I cd into a git repo
    parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }

    export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\[\033[32m\]\$(parse_git_branch)\[\033[00m\]\$ "
Because I often want to check recent files:

    alias llth='ls -hFlat | head'

Re: Ask HN: Best things in your bash_profile/aliases?

#145
post #56

Earlier quoted context omitted.

Bash has this as well set autocd

that would be rather shopt -s autocd

Yeppity.

> autocd If set, a command name that is the name of a directory is executed as if it were the argument to the cd command. This option is only used by interactive shells

Re: Ask HN: Best things in your bash_profile/aliases?

#146

This is tiny, but I've gotten a surprising amount of mileage out of aliasing 'fx' to firefox --new-instance --profile $(mktemp -d) which pops open a new instance of Firefox with a completely clean, temporary profile. Super useful for testing sites or add-ons without influencing (or being influenced by) by my normal browsing profile.

What would the Google Chrome equivalent look like?

Re: Ask HN: Best things in your bash_profile/aliases?

#147

alias ea='vim ~/.bash_aliases' alias ear='source ~/.bashrc' * i type 'ea' whenever i think a commands should aliased. * add new aliases * exit dan type 'ear' to refresh the bashrc. go for another productive terminale.

alias als="vi ~/.bash_aliases && . ~/.bash_aliases"

Re: Ask HN: Best things in your bash_profile/aliases?

#150
Some basic aliases I couldn't live without:

    alias rm='rm -i'
    alias mv='mv -i'
    alias cp='cp -v'
    alias ls='ls --color=auto -Fh'
    alias ll='ls -l'
    alias lla='ls -la'
    alias clean='rm -rfv *~ .*~ \#*\# .\#*\#'
    alias j='jobs'
    alias rm='rm -i'
    alias cp='cp -v'
    alias mv='mv -v'
Workspace management

    function workon () {
        LOC="$1"
        cd "${HOME}/work/$LOC"
        tmux attach -dt "$LOC" || tmux new -s "$LOC"
    }
Handle the git submodules nightmare (a little) more easily

    alias subupdate='git submodule init; git submodule sync; git submodule update --init --recursive;'
Colored prompt with git branch:

    PMT=" "; if [  $UID -eq 0 ];then PMT="# " ;else PMT="$ " ; fi
    WHITE="\[\033[0m\]"
    YELLOW="\[\033[0;33m\]"
    GREEN="\[\033[0;32;40m\]"
    BLUE="\[\033[1;34m\]"
    export PS1="[$GREEN\u@\h $BLUE\W$WHITE:$YELLOW\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)$WHITE]"$PMT
Run a quick web server

    alias simpleWebServer='python -m http.server 8888'
If you are using tmux, WSL, and ssh all together, you may sometimes need something like this (I always keep it in my bash_aliases and since never had color issues :)

    if [ "$TERM" == "screen" ]; then
        export TERM="screen-256color"
    fi
Post reply on HN