Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

251–260 of 288 posts

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

#251

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…

A colleague did a similar thing, except set it to whisper the time quietly at lengthy but random intervals.

It took the victim so long to figure out what was causing it, that it made it so much funnier.

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

#252
Cherry-picking some of them:

    # Show Disk Use of subdirectories, sort by size
    alias duss="sudo du -d 1 -h | sort -hr | egrep -v ^0"

    # Cheatsheet autogenerated from i3 configuration file
    alias i3cheatsheet="egrep ^bind ~/.i3/config | cut -d ' ' -f 2- | sed 's/ /\t/' | column -ts $'\t' | pr -2 -w 145 -t | less"

    # Show mount information in a nice format
    alias mountt="mount | column -t | sort"

    # Show remaining dirty bytes while coping to a file, very useful in XFCE not sure in other enviroments
    alias watchdirty="watch grep -e Dirty: -e Writeback: /proc/meminfo"

    
    # Bookmark directories ej. "bm a" "go a" etc
    go() { eval dir=\$$1; cd "$dir"; }
    bm() { eval $1=$(pwd); echo "`set | egrep ^[a-z]+=\/`" > ~/.bookmarks; }
    test -f ~/.bookmarks && source ~/.bookmarks

    # I use this one all the time, combined find+grep, f.e. fgr "Class" "*.cpp" "-l" (2nd and 3rd parameters optional"
    function fgr {
            NAM=""
            GREPTYPE="-i -H"
            if [ -n "$1" ]; then
                    test -n "$2" && NAM="-name \"$2\""
                    test -n "$3" && GREPTYPE=$3
                    CMMD="find . $NAM -not -path '*/\.*' -exec egrep --colour=auto $GREPTYPE \"$1\" {} + 2>/dev/null"
                    >&2 echo -e "Running: $CMMD\n"
                    sh -c "$CMMD"
                    echo ""
            else
                    echo -e "Expected: fgr  [file filter] [grep opt]\n"
            fi
    }

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

#253
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!

This is amazing! Just a note: I had to mkdir the directory in ~/.vim to get it work.

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

#254

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!

tar czvf

"create ze vucking file"

tar xzvf

"extract ze vucking files"

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

#256

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…

Thank you. It is so convenient to write some functions is .bash_profile. So powerful new skill.

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

#258

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…

Most of my colleagues used zsh and oh-my-zsh, and as far as I can remember, oh-my-zsh has a mechanism to check for updates every 14 days.

I would then set their .zshrc or whatever to end with

    echo "sleep 0.1" >> ~/.zshrc
so that every time they opened as hell, it would take 100ms longer to run. It would usually take them up to 1-2 second of startup time to figure out what was wrong.

Now my favourite part was that I edited the oh-my-zsh update script to actually echo the original echo line into their ~/.zshrc file, so that even if they figured out what was happening and were very vigilant with locking their laptop, it would happen again within the next 14 days. Loved that.

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

#259
I have few on my MBP that I use a lot

# CD to the root of the current git project

    alias ,,='git rev-parse --git-dir >/dev/null 2>&1 && cd `git rev-parse --show-toplevel` || echo "Not in git repo"'

# Put my MBP to sleep in X minutes

    sleep-in() {echo "Sleeping laptop in $1 minutes..." && sleep $((60 * $1)) && pmset sleepnow}
# Check CI status nicely using hub (hub.github.com)

    function ci {
      unbuffer hub ci-status -v $1 | sed 's/https:.*//'
    }
# Rerun the last git command with the suggestion it had

    alias yup='eval $(fc -ln -1 | sed "s/git/git -c \"help.autocorrect=-1\"/")'
# Look up directories for a Makefile and run it - I couldn't find a way to actually search up directories, so `detect` is my own binary that does that

    function make {
        if detect Makefile > /dev/null 2>&1 ; then
            LOCATION=$(detect Makefile)
            echo "Makefile found at $LOCATION"
            cd $LOCATION && /usr/bin/make $* && cd - >/dev/null
        else
            echo "Makefile not found"
        fi
    }

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

#260

#~/.inputrc is for nerds who don't want 1000-line bashrcs #C-w deletes previous word (by spaces) by default #bind C-q to delete previous word-segment instead of "start(?) term output" stty -ixon bind '"\C-q": backward-kill-word' #bind C-s to move cursor to previous [:space:] instead of "stop(?) term output" bind -r '\C-s' bind '"\C-s": shell-backward-word' #bind C-d to go forword, not crush the shell set -o ignoreeof…

I'll just add two more systemctl aliases I got

  alias scs='systemctl status'
  alias jc='journalctl --unit'
Post reply on HN