Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

161–170 of 288 posts

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

#161

    # ============= #
    # Bash-specific #
    # ============= #
    alias sudo="sudo --preserve-env"
    # Up & down map to history search once a command has been started.
    bind '"\e[A":history-search-backward'
    bind '"\e[B":history-search-forward'
    alias tmux="tmux attach || tmux new"
    alias fuck='sudo "$SHELL" -c "$(history -p !!)"'
    alias fucking="sudo"
    # ========================================================= #
    # GnuPG SSH Authentication                                  #
    # ========================================================= #
    # - Install "gnupg2" and "scdaemon".                        #
    # - Add "enable-ssh-support" to "~/.gnupg/gpg-agent.conf"   #
    #   - Or copy existing config from this repository          #
    # - Find [A]uthentication keygrips "gpg -K --with-keygrip"  #
    # - Add appropriate keygrips to "~/.gnupg/sshcontrol"       #
    # ========================================================= #
    which gpgconf 1>/dev/null 2>&1
    if [ $? -eq 0 ]; then
        export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
        gpgconf --launch gpg-agent
    fi

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

#162
post #135

Workspace management: export WORKSPACE="$HOME/workspace" alias ws='cd $WORKSPACE && ls' History related commands: alias h="fc -li 1" # like `history` but with dates # Which commands do I use the most? alias histstats="history | awk '{CMD[\$2]++;count++;}END { for (a in CMD)print CMD[a] \" \" CMD[a]/count*100 \"% \" a;}' | grep -v './' | column -c3 -s ' ' -t | sort -nr | nl | head -n10" Golang: alias gopath='cd $GOPAT…

What shell are you using? I'm using bash and don't have the `i` argument in my version of `fc`

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

#163

# ============= # # Bash-specific # # ============= # alias sudo="sudo --preserve-env" # Up & down map to history search once a command has been started. bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward' alias tmux="tmux attach || tmux new" alias fuck='sudo "$SHELL" -c "$(history -p !!)"' alias fucking="sudo" # ========================================================= # # GnuPG SSH Authentica…

You can use "tmux new -A" instead of two commands

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

#166

    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias d='docker'
    alias up='docker stack up --with-registry-auth'
    alias node='node --experimental-modules --experimental-repl-await --no-warnings'
    alias net='netstat -tunl'
    alias jurl='curl -sLH "Content-Type: application/json"'
    alias sb='source ~/.bashrc'
    rand() {
      openssl rand -base64 ${1:-15} | tr '+/' '-_' | tr -d '[[:space:]]='
    }
    randomstring() { LC_CTYPE=C tr -dc '[:print:]' /dev/null; echo; }
    serv() { docker run --rm --name "nginx-${1:-8000}" -p "${1:-8000}:80" "${@:2}" -v $PWD:/usr/share/nginx/html:ro caub/nginx-dev; }

    npmRegexp='^(i|init|install|link|list|ls|outdated|pack|prefix|prune|publish|r|rb|rebuild|restart|run|start|stop|test|tst|unpublish|up|update)$'
    n() {
      if [[ "$1" =~ $npmRegexp ]]; then 
        npm "$@"
      else 
        npm run "$@"
      fi
    }

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

#167
On Linux I use zsh, but these should translate.

Some of my favourite recent ones...

List most recently modified files from the current directory and any below it. Helps remind me what I was working with when I don't ssh into a box regularly :

  alias changedfiles="find . -type f -print0 | xargs -0 stat --format '%Z :%z %n' | sort -nr | cut -d: -f2- | head -n 20"
[ Need to tweak that sometime for BSD find on MacOSX, but I use it primarily on Linux ]

Before backing up from a Unix-typical filesystem to an ExFAT volume attached by USB, find problematic characters in filenames from the current directory and any below :

  function badnames {
	find . -name '*[?\\:*|\"]*'
  }

A big favourite on volumes with deeply nested directory structures. My favourite technique for a quick directory find and switch.

If you use FZF, this will show all directories (not files) from the current directory downwards. You can do an incremental fuzzy search by starting to type, and quickly change to that directory by pressing Enter when the desired one is highlighted.

  function fd() {
	local dir
	dir=$(find ${1:-.} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && cd "$dir"
  }
Love that one. As 'fd' is right under the fingers on the home row, the directory search and switch can look like magic when used quickly as part of the workflow.

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

#168
All of my various git alises. I especially like `goops` which is very useful if you just pushed some code and realised you missed something.

https://github.com/k0nserv/dotfiles/blob/7721559be40bba09cd8...

   alias gs="g status"
   alias glff="git pull --ff-only"
   alias glffc="git pull origin \$(current_branch) --ff-only"
   alias glc="git pull origin \$(current_branch)"
   alias gpc="git push origin \$(current_branch)"
   alias gpcfl="git push origin \$(current_branch) --force-with-lease"
   function goops { git add -A "$@" && git commit --amend --no-edit && gpcfl }
   alias gbr="git branch -r"
   alias grm="git branch --merged | grep -v \"\*\" | xargs -n 1 git branch -d"
   function mkb() {
       git fetch && git checkout -b "$1" origin/master
   }
`mkdataenv` is nice for spinning up a quick Jupyter environment for all data analysis needs.

https://github.com/k0nserv/dotfiles/blob/7721559be40bba09cd8...

    function mkdataenv() {
        mkvirtualenv --python /usr/local/bin/python3 $1
        workon $1
        mkdir "$1"
        cd $1
        pip install pandas jupyter numpy matplotlib seaborn
        pip freeze > requirements.txt
       jupyter notebook
    }

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

#169
post #154

Definitely not for everyone, but: set +H export HISTIGNORE="&" alias reset="printf '\033\143'" alias ls="ls --color=never -p -D '%Y-%m-%d %H:%M'" alias pmake="gmake -j30" PS1="\[\e[0;32m\][\w]$\[\e[m\] " history -w history -c I turn off history substitution (sometimes ! get into my program arguments and I don't like surprises), and start with no history on new terminals. I don't trust myself not to run an rm * from a…

I switched to a color schema where this dark blue is gone :-)

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

#170
post #135

Workspace management: export WORKSPACE="$HOME/workspace" alias ws='cd $WORKSPACE && ls' History related commands: alias h="fc -li 1" # like `history` but with dates # Which commands do I use the most? alias histstats="history | awk '{CMD[\$2]++;count++;}END { for (a in CMD)print CMD[a] \" \" CMD[a]/count*100 \"% \" a;}' | grep -v './' | column -c3 -s ' ' -t | sort -nr | nl | head -n10" Golang: alias gopath='cd $GOPAT…

What shell are you using? I'm using bash and don't have the `i` argument in my version of `fc`

I'm using zsh
Post reply on HN