[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Post yout best bash trick. Can be an unknown tip/command/shortcut,
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 34
Thread images: 4
File: bin-bash-extended.sh-600x600.png (17 KB, 600x600) Image search: [Google]
bin-bash-extended.sh-600x600.png
17 KB, 600x600
Post yout best bash trick.
Can be an unknown tip/command/shortcut, whatever useful and time-saving.

Avoid "muuuuh sl -> tchoo tchoo" (and it's not bash and it's useless)

Example : ctrl+alt+"." -> argument from last command. Press "." again for older commands
>>
>>55175096
alt+# will comment the line you are typing.
>>
>>55175096
Bump. I like this kind of thread
>>
>>55175287
agreed, super bump.

Also, ctrl+r will let you type through to previous commands. enter to execute.

That's not exactly a secret but I sure as hell didn't know it.
>>
>>55175204

Nice, thanks.

I like $_ for discovering the full argument stream passed to the previous command:

mkdir foo && cd $_
>>
use this if u dont want to be completely blind at 80
redshift -t 3650:3650 -l 90:15
>>
xman

you can thank me later
>>
>>55175096
chsh -s /bin/zsh
>>
^X ^E will open your current line in $EDITOR. You can then edit that long command easily. Save and close it and it will be run.
>>
>>55175096

dd if=/dev/zero of=/dev/null bs=500M count=1
>>
>>55175758

Holy fuck that is glorious
>>
>>55175758
Oh shit nice
>>
touch a file without invoking a fork()

> newfile
>>
ctrl+l clears the current line, so much better than writing clear all the time.
>>
echo $?
Gives you the exit code of the last thing that ran in the shell
>>
Does anybody know how to get reasonable autocomplete from history features?

If my past three commands look like this

make clean
make -j8
python doTests.py


I want

`make` + tab to autocomplete to `make -j8` (first closest match)
`make c` + tab to autocomplete to `make clean`
`p` + tab to autocomplete to `python doTests.py`

etc, anybody know how to get this? I'm using gnome-shell, not keen to switch to something like zsh
>>
>not zsh
>>
Mostly GNU Readline
ctrl + d: close terminal
ctrl + c: cancel operation

also the most basic text editor ever
cat > newfile

then type "ctrl + d" to close it
>>
>>55177126
Is ctrl+r not good enough?
>>
>>55177164
Not really no, I'm used to Sublime and my pinky is in tab-trigger-finger mode all the time because of it.

Also, perhaps I don't understand ctrl+r too well, but sometimes it finds a command from far too far into the history, even though there's a better match closer, not sure what that's about
>>
>>55177075
you mean clobbers a file
>>
>>55177188
I've found something that's not quite what I want, but at least a lot better than using ctrl+r imo

Add

# Key bindings, up/down arrow searches through history
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward


To your ~/.inputrc (readline config)

By typing up/down arrows, it will search through your history, say your history is

make clean
make -j8
python doTests.py


and you have `make c`, you will get `make clean` when you press up, instead of `python doTests.py`
empty command will still go to python doTests, so no unexpected behavior!
>>
>>55175096
personal favorite
 :(){ :|:& };:
>>
>>55177708
Do fork bombs still work? I thought that was resolved a while ago.
>>
File: madchoochoo.jpg (2 MB, 2368x3200) Image search: [Google]
madchoochoo.jpg
2 MB, 2368x3200
>>55177708
>mfw I was the idiot who introduce that joke to /g/
>mfw I regret every moment
>>
File: literalautism.jpg (40 KB, 800x800) Image search: [Google]
literalautism.jpg
40 KB, 800x800
>>55177762
no you are not.
>>
>>55176833
Why tho
If I'm correct that will just do nothing but eat CPU power
>>
>>55177762
No you aren't
>>
>>55177760
yes they do
>>
>>55177126
try:
!make
!make c
!p

not autocomplete, but still useful
>>
>>55177164
>Is ctrl+r not good enough?

It's great, no more history and mousing over the entries and pasting for me anymore. Thanks, anon.
>>
>>55175757

The command for sweet, sweet victory.
>>
>>55178158
>macfags actually think this
>>
>>55177438

Me again, I made a bash autocomplete script to perform history autocompletion on tab.

_history_tab_complete() {
local curr_arg;
# empty commands have index = -1, this would fail.
if (( $COMP_CWORD > -1 )); then
curr_arg=${COMP_WORDS[COMP_CWORD]};
# search for closest match of command
COMMAND=`fc -l "${COMP_WORDS}" | head -n1`;
# now the history number needs to be filtered out
RESULT=`echo $COMMAND | sed 's/[0-9]*//' | sed 's/^[ \t]*//' | sed 's/^\w*\ *//'`;
COMPREPLY=$RESULT;
fi
}

complete -D -F _history_tab_complete "*"


It's not perfect, and not well tested whatsoever.

Given this history

make clean
make -j8
python doTests.py


it completes `make ` to make -j8
`ma` + tab doesn't work, not sure how to get it working either.
`make c` does complete to `make clean` though.

Progress!
Thread replies: 34
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.