Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

131–140 of 288 posts

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

#131
post #80

Can I add something from .vimrc? If you put the commands: set undofile set undodir=~/.vim/undodir You get infinite undo in your files. Now when you go into a file, delete or add some text and close your terminal down, the next time you enter vim you can (re|un)do previous operations. Has saved my ass more times than I care to mention over my career!

You can also delete old (older than 90 days) undo files with the following in your .vimrc:

  let s:undos = split(globpath(&undodir, '*'), "\n")
  call filter(s:undos, 'getftime(v:val) 

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

#132
post #92

Here's a function you can use to generate a strong printable password on the fly: function gen_passwd () { openssl rand 150 |\ tr -dc '[:graph:]' |\ cut -c 1-${1:-13} } The default password length is 13 characters but you can pass a different length parameter instead. Explanation: * generate 150 pseudo-random bytes using openssl's rand * discard non-printable characters * cut to desired length Note that it will only…

I have similar but I remove some visually ambiguous chars.

  tr -d iIlLOo0

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

#133
I have aliases with the name of every project that open up a productive environment.

Eg. open a project with “Visual Studio Code” get latest version from git, reset db and run seeding. Then install dependencies and run dev server, while opening chrome at the right localhost address. I usually run the command walk away to get a drink or food and when I’m back everything is running so I can just start working!

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

#134

  function certchain() {
      # Usage: certchain
      # Display PKI chain-of-trust for a given domain
      # GistID: https://gist.github.com/joshenders/cda916797665de69ebcd
      if [[ "$#" -ne 1 ]]; then
          echo "Usage: ${FUNCNAME} "
          return 1
      fi

      local host_port="$1"

      if [[ "$1" != *:* ]]; then
          local host_port="${1}:443"
      fi

      openssl s_client -connect "${host_port}" /dev/null | grep -E '\ (s|i):'
  }

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

#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 $GOPATH/src && tree -dL 3'
Git:

    # --no-pager is underrated
    alias glnp="git --no-pager log --oneline -n30"
Misc:

    # Have I been pwned?
    # usage: `hibp email@example.com`
    hibp() {
        curl -fsS "https://haveibeenpwned.com/api/v2/breachedaccount/$1" | jq -r 'sort_by(.BreachDate)[] | [.Title,.Domain,.BreachDate,.PwnCount] | @tsv' | column -t -s$'\t'
    }

    # Weather
    alias weather='curl wttr.in/$CITY'

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

#139
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…

History with dates is genius! Thanks for sharing it :)

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

#140

One thing I do is to put this snippet in .bashrc or .profile for i in ${HOME}/.bash.d/*.sh do if [ -r ${i} ] ; then . ${i} fi done And drop some custom scripts in ${HOME}/.bash.d/ like alias.sh, env.sh (my common .bash.d scripts are saved in a git repository)

Whoa, I know someone who does exactly this. Is this a common pattern?

Unless you're him!

Post reply on HN