Hacker News new | past | comments | ask | show | jobs | submit login

My .bashrc is on a quest to turn my yakuake into the better half of vscode. "The shell is my IDE" is definitely true.

Though Google takes up a worryingly large fraction of it. Wonder if there could be a shell tool to just dump the first stackoverflow hit for a search.

bashrc highlights: https://gist.github.com/FeepingCreature/649588a2f6fa27c717bd...

- ctrl-G for "directory up"

- ctrl-E for "find and open in editor" (using fzf, substitute 'edit' with your editor of choice; the history gymnastics is to basically pretend that you typed it in manually for purposes of bash history)

- and of course, for german keyboard layout devs, rebinding capslock to alt-gr.




> Wonder if there could be a shell tool to just dump the first stackoverflow hit for a search.

There should be. I think `curl cheat.sh/programming+question` does that. There might also be a way to do that with surfraw. I just use DuckDuckGo, it almost always pops up an Stack Exchange answer in the sidebar when I search for something relevant to an SE.


I really love cht.sh, but find I never actually use it except for the occasional git syntax reminder. I think a flow that went `cht.sh -> fzf to narrow results and select a result -> vim -> OS clipboard` would have me using it all the time.


Funny, I have been asking this EXACT question on Linux forums and here for several months.

"How can I have a shortcut that I type, then enter a search query and have the first result open automatically?"


I have a fish function to open StackOverflow in Lynx. I can just do `stack how to write a function in fish shell`.


> Wonder if there could be a shell tool to just dump the first stackoverflow hit for a search.

I use https://github.com/samtay/so, which lets you search any stack exchange site (SO by default). It's fully terminal-based.


> and of course, for german keyboard layout devs, rebinding capslock to alt-gr.

I went the other way: use a US layout keyboard, and bind capslock to switch to German layout while capslock is being held down. I find that I need my fancy braces and brackets more than my umlauts. :)


I'm using US-intl (international) right now, supported everywhere I've seen. AltGr+q is ä, AltGr+s is ß, AltGr+y is ü, etc. Might seem weird at first, but it has most of the special or combined symbols you might need, not just German ones. Other than that, it's your usual US layout suitable for vim/evil, shell, coding, etc.


>Though Google takes up a worryingly large fraction of it. Wonder if there could be a shell tool to just dump the first stackoverflow hit for a search.

I saw this yesterday and your comment reminded me of it: https://github.com/danrobinson/tracestack

I kind of thought it was a novel idea, but kind of pointless - if you know how to read a traceback you can Google it... but I guess it makes a lot of sense depending on your workflow.


Didn't even realize you could bind control+key in bashrc. Definitely stealing some of those, thanks for the example!


Can you share how a drop down terminal figures in here as compared to a standard window?


I just like drop down terminals. :)


I have .. as an alias for cd ..


Don’t stop there!

... for cd ../..

....

.....

They compose naturally too, ..../targetDir

I use these so frequently and naturally that I forget that they aren’t built-in to my shell.

Also, a shortcut to jump between the last 5 or working directories. Print them with `dirs` and cd to a directory by invoking its number.


How do you make that history? Something like an alias for cd that pushes them onto a queue?


`dirs` is a shell built-in for the directory stack. If you supply it with -v, it will number the output. So the trick is just to make these line up, which is also really just using a feature of `cd` that extracts an entry from the directory stack at position n. My aliases look like this:

    alias dirs='dirs -v'
    alias '1'='cd -'
    alias '2'='cd -2'
    alias '3'='cd -3'
etc.

Doesn't seem like it would make a big difference, but it's very fluid and adopts well to whatever "you happen to working on in the moment."


I use "setopt autocd" in zsh. Typing the directory will cd into that directory. Any directory. No aliases.


Can you explain the fzf binding? I don’t get what’s going on there


Okay, the actual fzf call is just the $(fzf). But when you use a keybinding with -x, your shell executes the command directly. So when you press return in fzf, indicated by the exit code being zero, we additionally do three things:

- echo a facsimile of the prompt followed by the edit command so that it looks like you just typed "edit filename"

- insert that facsimile into the history buffer so that you can redo the edit command with arrow-up

- actually start the editor

- and clear the commandline of anything you may have written beforehand, which would otherwise still be there and break the illusion.

The reasoning behind this dance is that if you just do an ordinary bind, you just get the edit_fuzzy call in your bash history, which is pretty useless. You want the actual generated edit call, not the edit_fuzzy call. So we use bind -x and "pretend that you typed in the edit call manually". We could just make ctrl-E insert the edit command into the readline buffer, but then we'd have to press return twice.

${PS1@P} is "PS1, expanded as if it were a prompt (P)".


fzf can be used as a cool selector in the terminal, it just outputs what you picked from the list, so if you run `ls | fzf`, it will pass the list of files/dirs into fzf, where you can fuzzy search, select and it outputs to STDOUT.

So if you want to edit a file from inside a directory easily, you can do:

vim $(find | fzf)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: