Linux Terminal Goods
diego-pacheco.blogspot.com
diego-pacheco.blogspot.com
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.
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'.
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 :-)
Shell scripting is also the least painful way to call many external programs and glue them together into something useful. Calling external programs from “real” programming languages is far more painful.
If you need a real programming language, as you mentioned, use something designed for that.
(or was this comment intended for https://news.ycombinator.com/item?id=21013150 )
For a maintainable script pythons great of course.
When you use Bash, you benefit from an entire ecosystem that also uses it. That same ecosystem is not motivated to drastically change the shell, and therefore it remains stable and predictable.
Bash typically isn't like Python or JavaScript, where certain features are introduced at a particular version and you have to constantly check for them, or not use them outright, or maintain which binary you have installed at all times. One Bash binary typically contains the same feature set as another binary.
Bash isn't the friendliest thing to work with syntactically, but it's friendlier than the alternatives in maintability and reliability.
Despite all this, on the flip side, there still are a lot of people invested in alternatives, and some have gained plenty of traction. zsh is a great example.
> Bash typically isn't like Python or JavaScript, where certain features are introduced at a particular version and you have to constantly check for them, or not use them outright, or maintain which binary you have installed at all times. One Bash binary typically contains the same feature set as another binary.
While you're right about shell builtins (a lot of which are defined by POSIX anyway), to do anything useful in POSIX shells requires forking out to sed, awk, grep, as well as many other coreutils and CLI tools. Thus you then need to not only confirm whether those tools are also installed but sometimes also which version or even implementation they are (eg GNU extends on POSIX in quite a number of ways from supported features through to how you order and group flags. Sometimes it can be a little jarring jumping from Linux to OSX if you're used to GNU).
That said, I do working in shells. For "getting shit done" very little even comes close to shells in terms of productivity. However shells are generally optimised to the "write many read once" end of development rather than "write once read many".
As an aside, I suspect GP meant to post this comment on https://news.ycombinator.com/item?id=21013150 (Pure Bash Bible - also on the front page) rather than here?
You mention it as an aside, but I think it speaks to your point about external utilities. In that thread (I also think GP intended to comment on that topic), there was confusion to what "Pure" meant. The first sentence is, "The goal of this book is to document commonly-known and lesser-known methods of doing various tasks using only built-in bash features."
Bash's syntax is a bit rough at times and I often find myself having to Google things even though I know what I want to do at a conceptual level.
But the real magic isn't just Bash alone. It's combining it with Unix tools to pipe together programs to solve problems.
I guess at the end of the day no one has tried to fix it because they don't see it as a problem. Despite the syntax weirdness at times it's a pretty concise language which meshes well with writing ad-hoc things on the command line.
IMO Bash is often the best tool to use for a ton of different problems. Sometimes it's good for a final result and sometimes it's good to flesh out a prototype because you can hack something together so fast.
I fear it would take a massive coordinated switch, systemd-like, where an entire ecosystem moves to an alternative, to actually see any change in this area.
Yes, this is a huge deal in a good way. It's also why standalone zero dependency Python scripts are so successful since most systems have Python installed by default.
Although after reading your first sentence, I got excited. I thought you were going to write about how it's always there in the sense that if you're working in the terminal, Bash and friends are always right there at your finger tips. There's no context switch to get something done, which is super empowering for hacking together things to solve a problem. It just feels like the whole terminal environment in general was made to let tinkerers create the best possible system / workflows for them personally.
This seems to be the post you're replying to.
I know what you mean though. I always had to look up things every time. Lately I just committed a bunch of it to memory as it's useful enough and I'm pretty fond of it.
If you want to do that on a remote machine you just add this to the end of the command -ComputerName remotecomputer: Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer
And then you can just use the returned object to iterate over it: $disk = Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer -Filter "DeviceID='C:'" | Foreach-Object {$_.Size,$_.FreeSpace}
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...
Zshrc: https://gist.github.com/YoloClin/ffd82f441d292ccc5f25c62a80c...
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!
https://gist.github.com/archi/2a2331401842c0548fa8de0f69796f...
> 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.
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; }
.. () {
local arg=${1:-1};
while [ $arg -gt 0 ]; do
builtin cd .. &> /dev/null;
arg=$(($arg - 1));
done;
} up() {
local ups="."
for((i=0;i<${1:-1};i++)); do
ups="${ups}/.."
done
builtin cd "$ups"
}Though yours looks much nicer ^^"
I had a proof of concept, but hackernews doesn't support emojis :'(
Production root is made even more visually offensive.
Exactly. Drop-in compatibility with 'cat' is one of the goals of bat (see https://github.com/sharkdp/bat#project-goals-and-alternative... and a list of alternatives here: https://github.com/sharkdp/bat/blob/master/doc/alternatives....).
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.Vim can certainly do all these things (or mostly, I don't know about the terminal colors), but for viewing read-only text streams, it's a bit more domain-specific and convenient. It's also blazing fast to open, which vim isn't always.
* RipGrep: Replace Grep and it is blazing fast
* exa: Replace ls with many more options
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
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 }`
I wrote more about this here: https://lobste.rs/s/0kaozs/don_t_underestimate_grep_based_co...
export FZF_DEFAULT_OPTS="--ansi --preview-window 'right:60%' --preview 'bat --color=always --style=header,grid --line-range :300 {}'"
<stones thrown in the opposite direction>