Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

61–70 of 288 posts

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

#61
A well crafted $CDPATH helps me jump from project to project and from directory to directory within a project without having to type many ../:

    CDPATH=./:~/:~/Documents/:[...]
I often grep/ag stuff only to think afterwards that I should have done that from Vim, so I have this to rerun the previous command and feed its output to Vim's quickfix:

    vimq() {
    	vim -q 
Speaking of Vim, this one lets me open an arbitrary file from the current project in Vim without having to glob:

    vimf() {
    	vim +find\ **/*$1
    }
Create a directory and cd to it:

    mkcd() {
    	mkdir -p "$*"
    	cd "$*"
    }
It's not in my .bash_profile but I use this little command all over the place to get my IP address (and I need my IP address a lot):

    #!/usr/bin/env sh

    SYSTEM=$(\uname | \tr /a-z/ /A-Z/ | \cut -c-5)

    # MacOS
    if [ "$SYSTEM" = "DARWI" ]; then
    	\ifconfig | \sed '/vboxnet/{N;N;d;}' | \grep 'inet ' | \grep -v '127.0.0.1' | \awk '{print $2}' | \tr '\n' '-' | \sed 's/-.*//' | \tr -d '\n'
    	\exit 0
    fi

    # Linux
    if [ "$SYSTEM" = "LINUX" ]; then
    	\ip route get 1 | \awk '{print $NF}' | \tr -d '\n'
    	\exit 0
    fi

    # MINGW/CYGWIN on Windows
    if [ "$SYSTEM" = "MINGW" -o "$SYSTEM" = "CYGWI" ]; then
    	\ipconfig | \grep 'IPv4' | \awk '{print $NF}' | \tr -d '\n'
    	\exit 0
    fi

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

#62
post #20

I have a whole repository also including several dotfiles that I maintain for already several years [1]. Following are some snippets from the dotfiles/.alias and dotfiles/.functions files from that repository that probably are the most interesting and which I am using on a regular basis: # easier navigation alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." alias ~="cd ~" # Ge…

That extract function seems redundant. GNU tar already auto-detects the compression format of the archive, so `tar xvf archive.tar.xz` will work as expected (the J flag is not needed.) bsdtar does the same, and it supports formats other than tar, so `bsdtar xvf archive.zip` works too. These tools use the content of the file rather than the file extension, so they should be more reliable.

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

#63

Earlier quoted context omitted.

Hehe I liked the 'lcoate' one on this page too, same idea. It might be super-useful to have a function that, if command not found and if there's an anagram of what you typed that is a command, asks if you meant that instead, y/n? (That would make computers seem a lot more intelligent!)

You might be looking for this: https://github.com/nvbn/thefuck/blob/master/README.md

Thanks, but my computer's too old to read that page. It's a thing already?

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

#64
post #17
post #3

Since 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 .."

I have the same exact aliases but they check for a Git or SVN repo and then use the right tool accordingly. I also have `..`, but also `...` which maps to `cd ../..`

I also have '..' and '...', AND '....' heheh. I use that last one a lot

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

#66
post #3

Since 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.

side note: i started to get into zsh and then serverless. zsh was balking at finding node.js/yarn stuff and running commands. I had to revert back to bash

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

#68
post #36

Not as fancy as other tips here, but I bet this is really time saving in the long run for most developers. My core work is alway around ~10 directories, which are mostly code packages. As soon as I start working on a project/team, I create aliases for directories. They take the form: alias agg="cd /ws/ProjectName/src/PackageName/ && echo -n -e '\033]0;PackageName\007' && tab-color-devil-blue" The first part of course…

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.

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

#69

This is tiny, but I've gotten a surprising amount of mileage out of aliasing 'fx' to firefox --new-instance --profile $(mktemp -d) which pops open a new instance of Firefox with a completely clean, temporary profile. Super useful for testing sites or add-ons without influencing (or being influenced by) by my normal browsing profile.

This is great, thanks.

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

#70

A well crafted $CDPATH helps me jump from project to project and from directory to directory within a project without having to type many ../: CDPATH=./:~/:~/Documents/:[...] I often grep/ag stuff only to think afterwards that I should have done that from Vim, so I have this to rerun the previous command and feed its output to Vim's quickfix: vimq() { vim -q Speaking of Vim, this one lets me open an arbitrary file fr…

(It works, but..) What are all those backslashes for?
Post reply on HN