$ cat ~/bin/docker
#!/bin/bash
if [ "$DOCKER_HOST" != "" ]
then
HOST_ARG="-H $DOCKER_HOST"
fi
/usr/bin/docker $HOST_ARG $@
$ cat ~/bin/docker-compose
#!/bin/bash
if [ "$DOCKER_HOST" != "" ]
then
HOST_ARG="-H $DOCKER_HOST"
fi
/usr/local/bin/docker-compose $HOST_ARG $@Ask HN: Best things in your bash_profile/aliases?
21–30 of 288 posts
Re: Ask HN: Best things in your bash_profile/aliases?
#22 bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
This one automatically lists the files in the current directory, but limits the number of lines. function cd {
builtin cd "${@}"
if [[ "$(stat -c "%b" .)" -lt "100" ]]
then
if [ "$( ls -C -w $COLUMNS | wc -l )" -gt 30 ] ; then
ls -C -w $COLUMNS --color=always | awk 'NR Re: Ask HN: Best things in your bash_profile/aliases?
#23Since I'm working in git repos the majority of the time, I type these hundreds of times per day: alias s="git status" alias d="git diff" I prefer looking at this stuff in a terminal rather than an IDE. Reducing them to a single character just feels so good. Note: not a git alias like "git s", literally just the single character "s" in Bash itself. And coming in third: alias ..="cd .."
alias ..="cd .." If you use zsh, typing a directory name changes to it automatically. It’s almost always a very delightful thing.
Re: Ask HN: Best things in your bash_profile/aliases?
#24 alias fuck='sudo $(history -p !!)'
It runs the previous command as root.Re: Ask HN: Best things in your bash_profile/aliases?
#25 alias gs="git status"
alias gall="git add ."
alias gm="git commit"Re: Ask HN: Best things in your bash_profile/aliases?
#26Re: Ask HN: Best things in your bash_profile/aliases?
#27 cls="clear; ls"
It harkens back to DOS. Clearing the screen followed by ls happens surprisingly often, if not just to start things in "clean slate". I'm quite fond of it.Re: Ask HN: Best things in your bash_profile/aliases?
#28 function convert-decimaltobinary(){
n="$1"
bit=""
while [ "$n" -gt 0 ]; do
bit="$(( n&1 ))$bit";
: $(( n >>= 1 ))
done
printf "%s\n" "$bit"
}
function convert-binarytodecimal(){
echo "$((2#$1))"
}
function convert-hextodecimal(){
echo $(( 16#$1 ))
}Re: Ask HN: Best things in your bash_profile/aliases?
#29 # branches that were touched lately
nb() {
git for-each-ref --sort=-committerdate refs/heads/ -- format='%(committerdate:short) %(authorname) %(refname:short)' | head -n 10
}
# squash!
squash() {
if [ -n "$1" ]; then
git reset --soft HEAD~$1 && git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
fi
}
# open pr page on github for current branch
pr () {
local repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
local branch=`git name-rev --name-only HEAD`
echo "... creating pull request for branch \"$branch\" in \"$repo\""
open "https://github.com/$repo/pull/new/$branch?expand=1"
}
# check who uses port
port() {
lsof -i tcp:"$@"
}
# rebases local branch from origin /master and force pushes it
repush(){
git fetch origin master
git stash
git rebase origin/master
git push --force
git stash pop
}Re: Ask HN: Best things in your bash_profile/aliases?
#30This one is pretty useful! Open current OSX Finder directory in Terminal: cdf () { target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` if [ "$target" != "" ] then cd "$target" pwd else echo 'No Finder window found' >&2 fi }