3 ms·
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 cor
by ashelmire 8y ago
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'
- mttyng 8y ago> this gets the git branch to display when I cd into a git repo It's early and I'm lazy... will this always parse the branch upon entering any git directory?