My most used alias would be: alias fuck='sudo $(history -p !!)' It runs the previous command as root.
Ask HN: Best things in your bash_profile/aliases?
41–50 of 288 posts
Re: Ask HN: Best things in your bash_profile/aliases?
#42 sd () {
if [ -f "$*" ]
then
cd "$(dirname "$*")"
else
cd "$*"
fi
}
Also cwd which is like pwd but it also copies the current path to your clipboard. cwd='pwd | tr -d "\n" | pbcopy && pwd'Re: Ask HN: Best things in your bash_profile/aliases?
#43My most used alias would be: alias fuck='sudo $(history -p !!)' It runs the previous command as root.
Re: Ask HN: Best things in your bash_profile/aliases?
#44I have a whole repository also including several dotfiles that I maintain for already several years [1]. Following are some snippets from the dotfiles/.alias and dotfiles/.functions files from that repository that probably are the most interesting and which I am using on a regular basis: # easier navigation alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." alias ~="cd ~" # Ge…
Re: Ask HN: Best things in your bash_profile/aliases?
#45It 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 can use the histgrep function to search everything.
I keep meaning to make another processed file which would uniq the history without the datestamp and maybe hook into fzf, but this has been good enough for now.
# tricks from https://news.ycombinator.com/item?id=10162189
if [ ! -d ~/.history/$(date -u +%Y/%m/) ]; then
mkdir -p ~/.history/$(date -u +%Y/%m/)
fi
#cat .history/2016/09/* |sort -n| uniq
export HISTFILE="${HOME}/.history/$(date -u +%Y/%m/%d.%H. %M.%S)_${HOSTNAME}_$$"
export HISTSIZE=
export HISTCONTROL=ignoreboth
export HISTCONTROL=erasedups
export HISTTIMEFROMAT="%d/%m/%Y-%H:%M:%S"
#export PROMPT_COMMAND='history -a'
export HISTIGNORE='&:bg:fg:clear:ls:pwd:history:exit:make*:* --help:'
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
histgrep ()
{
grep -r "$@" ~/.history
history | grep "$@"
}Re: Ask HN: Best things in your bash_profile/aliases?
#46Re: Ask HN: Best things in your bash_profile/aliases?
#47My most used alias would be: alias fuck='sudo $(history -p !!)' It runs the previous command as root.
Re: Ask HN: Best things in your bash_profile/aliases?
#48Re: Ask HN: Best things in your bash_profile/aliases?
#49alias grpe=grep Nothing comes close to the amount of time I saved with this one.
Re: Ask HN: Best things in your bash_profile/aliases?
#50 # truncate the $PWD
function cut_pwd
{
newPWD="${PWD/#$HOME/\~}"
local pwdmaxlen=$((${COLUMNS:-80}/4))
if [ ${#newPWD} -gt $pwdmaxlen ]
then
newPWD=".+${newPWD: -$pwdmaxlen}"
fi
}
PROMPT_COMMAND=cut_pwd
PS1="\h:\${newPWD} \\$ "