
Linux Terminal Goods - diegopacheco
http://diego-pacheco.blogspot.com/2019/09/linux-terminal-goods.html
======
CoolGuySteve
Regular vim has tabs and you can bind any key you want to switching them (I
use F2/F3). The default is :next and :prev or gt/gT. I’ve been using the
feature for years now.

You can also open a list of files in separate tabs with the -p argument. So
“vim -p CppFile.*” will open the .h and .cpp in separate tabs for example. You
can then Y/p between the two buffers.

It’s so useful that I always “alias vi=vim -p” in my .profile.

~~~
leggomylibro
Is the '-p' necessary?

I like to open files in windows with e.g. "vim -O file1 file2", and I've
noticed that if I accidentally omit the '-o' or '-O', it opens each file in a
tab. Or at least, it opens each file in individual pages that you navigate
between with ':next' / ':prev'.

~~~
jolmg
The -p gives you a tab for every file opened. If you don't provide it, it
still opens them and you get a buffer for each one, but it doesn't open any
tabs. If you still get tabs even if you don't provide it, maybe you have a vim
plugin that's doing that.

------
wiz21c
I've just skimmed around it as someone who repeatedly need that kind of book
to achieve little things in bash.

I understand bash is the basis of so many things, that its importance is just
enormous.

But at the same time, I'm appalled by its syntax, idioms, etc. It's barely
readable for the casual reader that I am. I wonder why nobody tries to provide
a meaningful alternative. I've seen some (in python for example) but I'm kind
of surprised nobody puts more money in such an effort.

For example, the "trim string" function described at the beginning of the book
is horrible (although probably very clever). Why not simply provide a built in
function ? That would make code so much cleaner...

I ask the question honestly, it's not a rant :-)

~~~
pjc50
Generally if you're trying to do something that feels like a "program" in
shell script, rather than loosely gluing existing tools together, the
threshold for moving it into Perl or Python should be low. Even things like
trying to get the quoting right for lists of files some of which may have
spaces in their names is fiddly enough to drive people to writing a "proper"
program.

(or was this comment intended for
[https://news.ycombinator.com/item?id=21013150](https://news.ycombinator.com/item?id=21013150)
)

~~~
robohoe
The moment I have to use arrays in bash, I open up a python interpreter.
Syntax makes far more sense than in bash.

~~~
kjeetgill
I used to drop into python for ad-hoc work as soon as I needed even for/if or
any arithmetic. Now that I actually manage to remember how to use for-loops
when I need them and I picked up awk,I haven't needed to since.

For a maintainable script pythons great of course.

------
RadiantSecurity
I spend loads of time in a shell. One day I'll push my full dotfiles publicly,
but until then here's a few snippets I've found super handy. I'd advise
against using them verbatim but there's a few things in there that took some
time to figure out. Beware they can be somewhat buggy / break things though.

Highlights include:

\- Bind C-c/C-v to Copy/Paste, bind C-g to sigterm (Note: Breaks docker
interactive unless you mount bashrc into /etc/bashrc or similar!)

\- Autorun tmux on SSH session

\- Syntax/colour highlighting in zsh interactive, I think there's some
diff/less/man magic in there too!

\- Log all shell activity to .shell_logs (Be _super_ careful with this one,
breaking it could prevent you opening an interactive shell

\- Useful grep defaults, particularly relevant when using .shell_logs

Bashrc:
[https://gist.github.com/YoloClin/f4c82a6e693000a2da20e8029a4...](https://gist.github.com/YoloClin/f4c82a6e693000a2da20e8029a49656c)

Zshrc:
[https://gist.github.com/YoloClin/ffd82f441d292ccc5f25c62a80c...](https://gist.github.com/YoloClin/ffd82f441d292ccc5f25c62a80c78ad0)

One thing I've lost love for is Powerline9k - Right-aligned data breaks
copy/paste functionality, and patching fonts to get UI-arrows is fiddly for
little functional value. If I ever need to fiddle with that stuff again, I'll
configure a regular theme to do similar and go without the UI-arrow breaks.

I was considering hiding history-relevant log data (such as current system
time) to behind a carriage return, something like PS1="$(date)\r$PS1".

I'm interested in hearing others' cool, non-standard hacks!

~~~
archi42
Inspired by a colleague, I wrote this (for bash):

[https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f...](https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f58)

> up 4

go up 4 folders (=> "cd .." 4 times).

> up

goes up one folder, and you can repeat pressing ENTER to go up one more. Press
anything else to drop back to the shell.

Could probably be "better" (e.g. no subshells), but works well for me.

~~~
RadiantSecurity
Thats cool! I'm not sure where it comes from, but I get similar behavior in
zsh with 'cd ....' \- similar doesn't happen in bash though.

I mapped 'cd' to 'c' in my bashrc, but while doing it I also mapped 'c' to
execute 'ls' as the latter was basically muscle memory whenever I was using
cd. The .bashrc function looks like this:

c() { builtin cd "$@" && ls; }

~~~
imglorp
Hey guys, I have the same thing, but I called the command ".." (no it doesn't
conflict with the directory). ".." by itself is the same as ".. 3"

    
    
        .. () {
          local arg=${1:-1};
          while [ $arg -gt 0 ]; do
            builtin cd .. &> /dev/null;
            arg=$(($arg - 1));
          done;
        }

~~~
msoucy
Mine is similar, but only does one cd command - to allow better use of `cd -`

    
    
        up() {
            local ups="."
            for((i=0;i<${1:-1};i++)); do
                ups="${ups}/.."
            done
            builtin cd "$ups"
        }

~~~
archi42
"cd -" is equal to "cd $OLDPWD", so that still works with my function ;)

Though yours looks much nicer ^^"

------
lillesvin
Maybe I'm completely missing the point of `bat` but I usually just use `view`
(vim/neovim in readonly mode) if I want to read files with syntax
highlighting, GitGutter, line numbers, etc.

~~~
awake
Not sure if view lets you do this but bat will switch off highlighting if you
are piping output `bat file.txt | grep ...`. This makes it easy to make an
alias cat=bat and have everything work. Also you can make bat display output
with `less` and then line numbers can be toggled, not sure about gitgutter.

~~~
sharkdp
(author of bat here)

Exactly. Drop-in compatibility with 'cat' is one of the goals of bat (see
[https://github.com/sharkdp/bat#project-goals-and-
alternative...](https://github.com/sharkdp/bat#project-goals-and-alternatives)
and a list of alternatives here:
[https://github.com/sharkdp/bat/blob/master/doc/alternatives....](https://github.com/sharkdp/bat/blob/master/doc/alternatives.md)).

Another thing that I use frequently is previewing a whole set of files in a
single (pager) output. Something like

    
    
        bat src/*.cpp
    

This also allows you to easily search across a whole set of open files.

~~~
OskarS
Awesome work. I've been a happy user of bat for a few months now, I've almost
totally trained my brain away from typing cat.

------
diegopacheco
Part 2
[https://news.ycombinator.com/item?id=21119949](https://news.ycombinator.com/item?id=21119949)

------
CiTyBear
Other stuff with _asteroids_ :

* RipGrep: Replace Grep and it is blazing fast

* exa: Replace ls with many more options

------
profunctor
Diego I think you're using the word asteroids where you mean the word
steroids.

~~~
Mic92
Would be cool though, if somebody would use vim on asteroids.

~~~
twic
Yeah, but on Mars they use Emacs, so then it's just The Expanse all over
again.

------
jeromescuggs
i really wish spacemacs didn't have that pretty lame loading screen, as a
spacevim devotee i found alot of things that spacemacs does that specifically
address some issues i have with spacevim.

i know the correct path forward here is, of course, diving into the guts of
spacevim and tinkering until it works for me, but i will post one quirk as it
will probably be some time before i will be able to write my own comprehensive
plugin:

the hugofy/markdown plugins seem to all do this awful thing in which they
render the markdown on the fly. it's kinda neat for basic text formatting, but
my god it is an utter nightmare if you have any sort of URL's or images,
because the second you key in that second bracket, it suddenly dissapears and
you're left having to basically guess your way through the process of typing
the url and closing out the shortcode.

if someone knows of a markdown editor that plays nice, i'd love to see it.
hope im not overlooking something painfully obvious here

anyways, i picked a hell of a time to dive into the commandline, a year ago i
came across scoop/chocolatey and quickly discovered WSL, and thanks to a
phenomenal amount of work by some great folks (even you, Person Reading This),
my desktop is not much more than the lobby i pass through before going to
where the magic happens:
[https://imgur.com/a/iCpWZAC](https://imgur.com/a/iCpWZAC)

~~~
weaksauce
What about the loading screen do you dislike? I believe you can change the
default after it loads up(and you generally want to be using a daemon in the
background with Emacs so it’s a first time run thing mainly anyway)

------
xvilka
Just one link: [https://terminalsare.sexy](https://terminalsare.sexy)

------
ddalex
I prefer my terminals dumb and without much color, as the UNIX gods intended
them to be.

This being said, I'm in love with `fzf`, my workflow improved markedly after
scripting (on mac)

`ggvi() { git grep "$@" | fzf | sed \"s/:/ +/\" | cut -d \":\" -f 1 | gxargs
-r -o vim }`

~~~
mkesper
You can also combine it with ripgrep. Much faster than git grep.

~~~
ddalex
I actually time-tested git grep vs ripgrep, and I'm not seeing meaningful
differences on my repos. ripgrep smokes regular grep but for some reason git
grep is just as fast as ripgrep

~~~
burntsushi
Because benchmarking these tools is difficult to do correctly, and is heavily
workflow dependent. If your search space is small, them it doesn't really
matter what tool you use for example, they are all probably going to be pretty
quick.

I wrote more about this here:
[https://lobste.rs/s/0kaozs/don_t_underestimate_grep_based_co...](https://lobste.rs/s/0kaozs/don_t_underestimate_grep_based_code#c_vddxv7)

------
temo4ka
This post is relevant:
[https://news.ycombinator.com/item?id=17874718](https://news.ycombinator.com/item?id=17874718)

------
myartsev
fzf + bat seems pretty nice!

export FZF_DEFAULT_OPTS="\--ansi --preview-window 'right:60%' \--preview 'bat
--color=always --style=header,grid --line-range :300 {}'"

------
vectorEQ
some vim enthousiast here scalded me for sending him spacevim linkand told me
to use neovim. i don't use vim so i wouldn't know, and vim people seem easily
offended :D. anyhow, just thought i'd not his input.

~~~
packetlost
Spacevim actually has some original features (kind of ripped off from emacs)
that I _really_ like, and can't find a way to get without using Spacevim.
There's nothing wrong with using it, but most vim users like to start from
scratch and build their own experience to meet their specific needs. Starting
with something like Spacevim is 100% ok if you've never used vim before, but
most people end up moving onto the more 'custom' experience eventually anyway.

------
z3phyr
Why are dark themes considered cool? Am I missing something?

~~~
C0d3r
Easier on the eyes, at least for me.

------
raveenb
this is super awesome! love it, thanks for sharing spacevim is exactly what I
have been looking for

