Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

271–280 of 288 posts

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

#271

My favorite new one that I have been using a lot: function cheat() { curl cht.sh/$1 } It queries the cht.sh cheatsheet of various Unix commands. 'cheat tar' prints: # To extract an uncompressed archive: tar -xvf /path/to/foo.tar # To create an uncompressed archive: tar -cvf /path/to/foo.tar /path/to/foo/ # To extract a .gz archive: tar -xzvf /path/to/foo.tgz # To create a .gz archive: tar -czvf /path/to/foo.tgz /path…

This is awesome, I ALWAYS have to google for how to untar an archive (I don't do it often enough to commit to memory) thank you!

I have an alias "x" setup to run:

      atool --extract $*
That will unpack "anything", into a sub-directory if necessary. Something I use more than any other alias.

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

#272
post #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!

I do that in my dotfiles too:

The main include:

https://github.com/skx/dotfiles/blob/master/.bashrc

The actual dotfiles:

https://github.com/skx/dotfiles/

(People usually copy the literate emacs configuration ..)

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

#273
post #262
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'm trying to use this in mac shell, but it says `tr: Illegal byte sequence`

Try setting LC_CTYPE:

  env LC_CTYPE=C tr ..

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

#274
These are probably the 3 I find most useful:

Copies the directory of the current git dir into the clipboard.

    which pbcopy &> /dev/null
    if [[ $? -eq 0 ]]; then
        CLIPBOARD_COMMAND="pbcopy"
    fi
    which clip &> /dev/null
    if [[ $? -eq 0 ]]; then
        CLIPBOARD_COMMAND="clip"
    fi

    cpgitdir() {
        GIT_DIR=`git remote show -n origin | grep "Fetch URL" | sed -e "s/  Fetch URL: //"  | tr -d '\n'`
        echo "Copying git dir to clipboard: $GIT_DIR"
        echo $GIT_DIR | tr -d '\n' | $CLIPBOARD_COMMAND
    }
Allows you to split your .bash_profile into multiple .bash_profile files for clarity

    if [[ -d ~/.bash_profile.d ]]; then
        for file in `find ~/.bash_profile.d -type f`; do
            source $file
        done
    fi
Simple calculator

    calc () {
        bc -l 

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

#275

Earlier quoted context omitted.

In my previous setup, I had a function that displayed a menu when I started bash, listing all my "main" directories. So each time you started a session you just had to press 1-7 to go where you wanted.

That is a great idea. Thank you!

Definitely save me some time and effort. The only issue I had was that sometimes when I wanted to use bash from, like, another app it would start the menu so it wouldn't work to use it from them. I'm sure it can be worked around but it was never a real issue so I didn't work on it.

Here is the code I had https://gist.github.com/jontelang/c6317bf14c527d2a89f1efd5d0... and I put this straight into my .bash_profile and it runs automatically when the shell starts.

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

#276

Something funny: alias crontab='fuck you, ' Background: Everyone knows that in a [in]sane workplace, you ALWAYS have to lock your machine. So this particular new hire forgot to lock her machine and one of the seniors (senior prankster, I would say) jumped into her terminal and set a crontab to run EVERY MINUTE. So she comes back (we pair program so they were actually pairing that day) and goes on with programming for…

should be:

say 'fuck you, '

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

#277
post #254

Earlier quoted context omitted.

This is awesome, I ALWAYS have to google for how to untar an archive (I don't do it often enough to commit to memory) thank you!

tar czvf "create ze vucking file" tar xzvf "extract ze vucking files"

Lol.

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

#279
Love this thread! Some of mine (excluding similar to what has already been mentioned):

  alias cleangopro="rm -rf /Volumes/GOPRO/DCIM/*"
  alias mkdir="mkdir -pv"
  alias ssh="ssh @"
  alias clearmail='sudo rm /var/mail/'
  alias flushcache='dscacheutil -flushcache && sudo killall -HUP mDNSResponder'
  alias listenforpwd="sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -B5 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user '"
  alias listenforuseragent="sudo tcpdump -vvAls0 | grep 'User-Agent:'"
  alias listenforgetreq="sudo tcpdump -vvAls0 | grep 'GET'"

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

#280

Love this thread! Some of mine (excluding similar to what has already been mentioned): alias cleangopro="rm -rf /Volumes/GOPRO/DCIM/*" alias mkdir="mkdir -pv" alias ssh ="ssh @ " alias clearmail='sudo rm /var/mail/ ' alias flushcache='dscacheutil -flushcache && sudo killall -HUP mDNSResponder' alias listenforpwd="sudo tcpdump port http or port ftp or port smtp or port imap or port pop3 or port telnet -lA | egrep -i -…

SSH has a configuration file (.ssh/config) which lets you set configuration for specific hosts and even aliases:

    Host reproserver
    User remi
    Hostname 128.122.217.96
    IdentityFile ~/.ssh/id_rpz
Post reply on HN