Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

81–90 of 288 posts

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

#81

I've used these so much: function gc() { grep -rnI "$@" * ;} function gcA() { grep -rnI -A 5 "$@" * ;} function gcB() { grep -rnI -B 5 "$@" * ;} function gcC() { grep -rnI -C 5 "$@" * ;} function gcf() { grep -rnIl "$@" * ;} Just helper functions built on top of grep

And what do they do? It's not obvious. edit: Thank you both!

-r searches directories recursively instead of single files; -n displays line numbers; -I ignores binary files. -A, -B, -C, and -l set how much context is shown: 5 lines of content before the match, after the match, or both; or just the filename and no content.

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

#82

This one is pretty useful! Open current OSX Finder directory in Terminal: cdf () { target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` if [ "$target" != "" ] then cd "$target" pwd else echo 'No Finder window found' >&2 fi }

can't you just wite "cd" and drag the folder into the terminal?

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

#83
In my bash_profile is a simple echo which makes the shell say hi to me every time I open an instance. Brightens my day a little bit:

  echo 'Hello dude '
As an iOS dev, this one is super useful:

  alias cdd='rm -rf ~/Library/Developer/Xcode/DerivedData/* && echo "Cleared DerivedData/"'

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

#84
Not strictly an alias, but autojump has been a huge productivity booster for me. Installing it sets up an alias of `j` which guesses the best directory to cd to based on your cd history.

So instead of having to type `cd ~/Projects/someproject` you could just type `j some` and it'll end up there.

https://github.com/wting/autojump

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

#86
post #53

One useful alias I have not seen mentioned here is this: alias myip='curl -s https://api.ipify.org' Just prints out my current public IP address. I also have a bunch of others mentioned in this thread, and I've abbreviated a bunch of self-explanatory docker-compose commands, e.g. dcdown, dcup, dcrestart, dcpullup, etc

  curl ifconfig.me
is also easy to remember

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

#88

In my bash_profile is a simple echo which makes the shell say hi to me every time I open an instance. Brightens my day a little bit: echo 'Hello dude ' As an iOS dev, this one is super useful: alias cdd='rm -rf ~/Library/Developer/Xcode/DerivedData/* && echo "Cleared DerivedData/"'

cdd seems like a bananas alias for something that does an rm -rf!

Have you ever done it by mistake?

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

#89

I've used these so much: function gc() { grep -rnI "$@" * ;} function gcA() { grep -rnI -A 5 "$@" * ;} function gcB() { grep -rnI -B 5 "$@" * ;} function gcC() { grep -rnI -C 5 "$@" * ;} function gcf() { grep -rnIl "$@" * ;} Just helper functions built on top of grep

And what do they do? It's not obvious. edit: Thank you both!

-r enables recursion

-n enables line numbers

-I (eye) ignores matches on binary files

-l (ell) lists the filenames of matching files only (overrides -n)

-A, -B, and -C specify how many lines of context after, before, or around the match to display.

"$@" adds any additional command line arguments passed to the functions.

* selects all the files and directories in the current directory.

So, without other arguments, the first four functions list matches with line numbers for all files (ignoring binary files) in the current directory and below, with 0 lines context (match only), 5 lines context after, 5 lines context before, and 5 lines context around the match respectively. The final function lists the filenames only and provides no context or line numbers.

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

#90

In my bash_profile is a simple echo which makes the shell say hi to me every time I open an instance. Brightens my day a little bit: echo 'Hello dude ' As an iOS dev, this one is super useful: alias cdd='rm -rf ~/Library/Developer/Xcode/DerivedData/* && echo "Cleared DerivedData/"'

cdd seems like a bananas alias for something that does an rm -rf! Have you ever done it by mistake?

It doesn't really matter; the directory is Xcode's auto-generated build products and can be recreated quite easily.
Post reply on HN