lainchan / Ω
Shells (the terminal kind)
Vasya Pupkin · 2017-12-28 09:15
What shell are you using and why, lain? Any cool utilities you use in your shell that make it much more enjoyable?
I recently switched from bash to zsh and I've found it very enjoyable. It helped that my .bashrc was fairly minimal and I didn't need to do any more than copy/pasting some export statements for some variables I use for a project I'm working on atm.
The thing that I really like about zsh is its autocompletion. You can write scripts that define how zsh should autocomplete certain commands. For example, in bash, typing "man 3 print<TAB>" does nothing, but in default zsh, there's a function that will show you the possible appropriate completions, e.g. printf, print_description, etc. There's a lot of these functions defined for things like man, git, kill, etc., that make terminal life much more pleasant.
It also has a Vi (or Emacs) mode for editing. Perfect for me, since I've had many frustrations reaching the end of a line of a bash command, then habitually hitting <ESC>^ to change a typo at the start.
After making this switch, I'm curious as to what the benefits of some the other shells are. Any lains use something other than bash or zsh?
For utilities, I've recently added `alias cat=colorize` and installed `z`. colorize is just cat, but with syntax highlighting, and z lets you cd to directories based on the frecency of their use. I also wrote a short script (in bash, not zsh) for quickly transferring a file via scp that I've used over a hundred times.
J.C. Denton · 2017-12-28 14:24
>>6832
I use fish, because I really like its completion of entire commands. I got it working in zsh via an extension once, but it would forget my commands after I closed the shell. Other than that I did configure my dotfiles to work in zsh once, and it was kind of nice, but I'm a bit used to fish scripting now. It uses `end` instead of `done` or `fi` or `esac`, and there's no `do` or `then`. Also, you use the special builtin commands "and" and "or" instead of && and ||, which is nice.
Hagbard Celine · 2017-12-28 14:44
I use bash, never really felt the need to use anything else
Spooky · 2017-12-28 15:49
>>6832
>You can write scripts that define how zsh should autocomplete certain commands.
So does bash: https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion
>It also has a Vi (or Emacs) mode for editing.
So does bash (readline): https://www.gnu.org/software/bash/manual/html_node/Readline-vi-Mode.html
Also, I'd argue that pressing <C-a> is faster than <Esc>I.
I use zsh too (mostly because a few vi-editing features are available in zsh but not in readline) but bash and zsh are quite similar.
>>6836
> there's no `do` or `then`
You can also do that in zsh with setopt short_loops.
Donna Hawthorne · 2017-12-28 16:22
>>6839
The impression I get is that zsh just has nicer defaults and a more vocal community than bash.
Emmanuel · 2017-12-28 18:00
Ive ended up using rc because between the not gross syntax and the fairly short manual page its the only shell I ended up mostly learning.
William Holtzer · 2017-12-28 18:51
>>6839
>readline
>vi mode
Why have I never heard about this before? This is great, thanks lainon!
Tyrell Wellick · 2017-12-28 19:22
>>6846
is that the plan9 shell?
Agent Richard Gill · 2017-12-28 19:28
I use sh because JIT languages with syntax highlighting and completion are waste of processor and brain ticks.
I do my file browsing in file browser and text edititing in word processor.
Crash Override · 2017-12-28 19:44
es, which does everything I want it to. Inspired by rc, but isn't developed anymore. This is fine, because I can extend it myself (which it was designed to allow).
>>6848
Yes.
Naomi Nascimento · 2017-12-29 22:45
I don't really understand the point of the different ones. Shells are just a programming language made specifically for working with the OS itself. It's all just personal preference, right?
Debbie Charteris · 2017-12-29 23:04
>>6885
>I don't really understand the point of the different ones.
>It's all just personal preference, right?
You answered your own question.
XERXES · 2017-12-31 06:40
>>6885
>I don't really understand the point of the different ones. Shells are just a programming language made specifically for working with the OS itself. It's all just personal preference, right?
Yeah, pretty much.
>>6853
Reading into es, it seems neat. What about es do you like, aside from the extensibility? What extensions have you written for it?
Yet Another Lainon · 2018-01-02 00:41
>>6930
>Reading into es, it seems neat. What about es do you like, aside from the extensibility? What extensions have you written for it?
I don't use Emacs, but think it's pretty much the same philosophy. Core written in C, with the main functionality on top in a functional language. Of course, es isn't Lisp, but it is in fact functional. There are lots of hooks so you can mould it to do most of what you want.
One thing I missed switching from tcsh was the option to see how long your command took it if it ran for more than a certain amount of time. The REPL is written in the es language, so I just edited it to do the timing. You can add job control (not in stock es AFAIK), change how `cd` works, output times for each command in a pipeline, etc.
Bash has convenient history expansion so you can do `!!` or `!$` to refer to parts of the command history. That's something that you could add to your shell, and I'll probably do just that at some point.
Cereal Killer · 2018-01-11 17:02
>>6832
bash, mostly because I'm used to it.
>For example, in bash, typing "man 3 print<TAB>" does nothing,
I use:
: ${MANPATH:=/usr/share/man:/usr/local/share/man}
_man_gen() {
local manpages="${HOME}/.man"
[[ -r "$manpages" ]] || _find_man > "$manpages"
declare -ag _MAN_INDEX
mapfile -t _MAN_INDEX < "$manpages"
}
_find_man() {
local IFS=:
find $MANPATH -type f | sed -nr '/\.[[:digit:]](\.gz)?$/{
s|^.*/||g;
s/\.[[:digit:]](\.gz)?$//;
p;
}' | sort -u
}
_man_gen
complete -W "${_MAN_INDEX[*]}" -o default man
Admittedly, it could use some cleanup, but it works.
Leto Atreides I · 2018-01-13 12:34
>>6843
Zsh also has a few nice features such as zcalc or zmv and the way it deals with hooks (pre-cmd, post-cmd...) is a bit nicer that the way bash does it (I believe you're only allowed to have one function in bash while zsh uses an array).