I'm not sure why this isn't a part of zsh already, but if you want to see the last few commands you ran in the current directory, that little utility will do that for you. Great for reminding yourself what you did last time you were in a directory.
When I was exploring projects that did this I found an alternative that spun up a database and was literally thousands of lines of code. This seemed to fit exactly what I was looking for without insane levels of overhead.
This is called Inbound Marketing, which consists of creating actual useful content slightly tangential to your own product/service so to attract audience which will, potentially, convert to customers.
Sometimes it’s well executed (see Realm’s) sometimes it’s not.
If you’re on 10.15 (Catalina) there’s no need to install zsh, it is the default shell. If you’ve upgraded and are still using bash, just do ‘chsh -s /bin/zsh’ to set the default to zsh.
What was the reason for them doing this do you know? From my experience with it over the last year, zsh is slightly worse at autocomplete than bash, with no advantages.
Is there something I'm missing, like a good default .zshrc?
To be precise - Apple was stuck on the last GPL 2 version of bash and finally gave up and moved to zsh which doesn’t have the GPL 3 license but is bash compatible and they can keep it updated.
I had done that, but my ssh completions weren't working great at all. I've installed ohmyzsh as recommended below and it's great, definitely a step up from bash.
What I would like is a blog post about making zsh less different than bash. I'll get to the mind-blowing tricks eventually, but for now I want the old tab completion and word stops back. Maybe I should just chsh back to bash, but the macOS copy of bash is really old now.
Last time I checked it was slower than https://github.com/romkatv/powerlevel10k, because it doesn't decouple the rendering of the prompt from the background processes collecting status information. Ergo no instant prompt. Also, some other cool tricks w.r.t. prompt vs. backscroll.
It seems fast enough but once you enter an actual directory of code where it needs to get the version of node, kotlin, package, etc it slows down noticeably. I've ended up disabling most packages because it is absurd to (I assume) be running node --version every time a prompt is generated.
It's a shame they can't do these things asyncronously or cache them.
Caching is a bit dangerous, and most shells don't support asynchronous prompt updates. And cross-shell support seems to be a prime feature. Spending probably a lot of effort just for improving zsh experience might just not have been important enough yet.
The power of powerlevel10k is that it can draw the plain prompt immediately, and respond to keyboard immediately, and then backfill any advanced prompt information (and properly shifting the already added text to the right and wrapping it correctly). I know that zsh has support for this, and bash does not (powershell neither); my prime reason why I use zsh. Fish, I don't know how it handles prompts.
This is very powerful in large git repos etc. You're never waiting for the prompt. You just type immediately, w/immediate response. So, you only wait for the status information to show up when you need it. So you also don't pay an excessive penalty if you prefer overly chatty prompts.
AFAICT the lazy-loading and async-support tickets above talk about internal implementation details, timeout support (so cancelling stuff like a too slow status report and showing a simplified prompt). I may misunderstand that, I only gave it a quick glance.
Maybe starship already supports this for zsh, or not, but at least they don't promote it front and center.
zsh4humans is the most recent zsh “trick” I’ve discovered. zsh is a bit like emacs when first installed: it can do a lot of things but it’s not nearly as useful without a lot of manual configuration. I’m honestly surprised it doesn’t have more stars on GitHub.
Is this similar to Oh My Zsh [1]? I personally have been using Oh My Zsh for years and I've always been a fan of it. I can quickly add themes and plugins and have my shell ready to go how I like it quite quickly on new systems.
zsh4humans is like ohmyzsh but much better IMO because when you first install zsh4humans, it walks you through a setup wizard that walks you through choosing your fonts, prompt style, completion style, etc. and automatically installs the appropriate zsh plugins and things like powerline fonts according to your choices.
Oh wow, that actually sounds much nicer! I wonder if it's worth switching to this or if I may as well stay with ohmyzsh for now and switch to zsh4humans in future installs.
I'd guess that xorcist added a space at the end of the function name because zsh uses =( to specify one type of process substitution. Without the space or an escape for = zsh will error on alpaca128's definition believing you wanted something else entirely.
To that point zsh has some excellent additions for process substitution beyond bash's <(list), but it also makes for yet more weird incompatibilities for when that matters. I only looked at this to start with because I assumed the space was because =() would have been treated as the full path modifier for a command called (), because it would mean that with any other character including other bracket types. TIL.
> Just a little shortcut but REPLs like Python's take a while to spin up, so it's pretty convenient.
Really? Loading python takes basically 0 seconds for me... the slowest I could get running `time python3` and hitting ctrl-d (to exit) is like 0m0.104s.
my favourite is pari/gp, that can be used as a simple calculator, but also has quite fancy math at your fingertips. For example, it is the easiest way to compute entire series: you type "exp(sin(x))" and you get "1+x+1/2*x^2-1/8*x^4-1/15*x^5 ..."
It isn't shown in TFA, but the zcalc keymap is bindable in the line editor so not only can you use it like qalc/irb/luap/whatever you can also take advantage of any other functionality of zsh within it. Admittedly, you could do some of that with some magic $if/$endif guards in your ~/.inputrc if your REPL uses readline, but the integration is nice functionality if you're a heavy zsh user. I think of it more like the expression register in vim or eval-print-expression in emacs.
These are provided by Readline. Many command line programs support Readline, and for those that don’t, rlwrap is like magic (even automatically adds history!).
This is always my complaint about posts like this. I read them looking for the killer feature to make me consider switching from bash and it's always stuff bash does natively or with a one line alias.
I'm happy in zsh or bash but the one thing I love in zsh is that completion options for program arguments. Having a list with a snippet of documentation to tab through is a huge benefit.
IIRC, bash doesn't support extended completion editor features of ZSH, which GP alluded to - like generating a table of options with help strings that can be selected by arrow keys and the like.
> rsync --e«TAB»
Completing file
some-file-with-extra-hyphens
Completing host
a-n-example.local
Completing option
--cvs-exclude -- auto-ignore files the same way CVS does
--delete-excluded -- also delete excluded files on the receiving side
--exclude -- exclude files matching pattern
--exclude-from -- read exclude patterns from specified file
--executability -- preserve executability
--ignore-existing -- ignore files that already exist on receiving side
--ignore-non-existing --existing -- ignore files that do not exist on receiving side
There are various ways to present the completion; I have the simple "keep typing letters" way, but Zsh can also present a table with an entry to highlight.
Yes, but on the other hand most proponents of zsh have installed ohmyzsh and a dozen plugins. (Just like a lot of long-time users have a long .bashrc.)
A "dizzying assortment of features" is not automatically a good thing.
The features need to be able to do useful things better somehow, and that's where articles demoing such applications come in.
"Better" also doesn't necessarily mean "more concise," otherwise APL would be one of the best programming languages. A language with a smaller number of accessible, comprehensible, memorable features can prove more useful in practice than one with a "dizzying assortment" that's hard to remember, difficult to read, etc.
I've used Zsh for 15 years or more, and when I started I read the manual. (I realize this is unthinkable nowadays.)
I noted down the things I thought would be useful day-to-day, and started using them. A few months later, I skimmed through the manual again. I still do so, every year or two. My work gradually changes, and I find Zsh has features that are now useful to me.
There are an endless number of programs I could be using. There are an endless number of programs you could be using.
The issue is how to decide whether something is worth looking at.
An article which gives examples that can easily be achieved by some more mainstream system is unconvincing. That's what was being discussed here:
> This is always my complaint about posts like this. I read them looking for the killer feature to make me consider switching from bash and it's always stuff bash does natively or with a one line alias.
Do you know why "bash does [these things] natively"? Because zsh had them 20 years ago when bash was barebones and people were envious and over time bash started copying these features over. Sometimes poorly.
And for the "one line alias", in a bunch of cases it's with additional commands, which are not always available, the most famous example being rename.
Which rename? The binutils one (I think) or the Perl one (which has more features)?
I agree. I have been using Zsh since about early 1993. I went through a pretty thorough "first I'll convert to tcsh!" then "to Bash!" then "to Zsh!" evaluation back then and Zsh was absolutely the clear winner.
While Bash has "caught up" some in the ensuing decades by copying features (some poorly as you note), I think it still misses quite a few nice "usability" features. I've listed some here [1] from memory, but I am probably forgetting other pretty nice ones. Like maybe ${(f)"$(mycmd)"} to split the output of `mycmd` strictly by newlines. (or ps:\0: for even stricter splitting).
As many others here have noted, terse syntax for things like `repeat` loops or normal `for`/`while` loops or shell var expansion can all be addictive, but some specific things I miss in Bash that are easy in Zsh are:
1) auto cd to any evar just from its name
e.g. lb=/usr/local/bin; lb
($lb works in bash, but I always forget
the $. I know I could do aliases...Yuck.)
2) auto cd does not seem to use $CDPATH
this is a real pain since I am used to
never typing "cd ".
3) **c instead of **/*c for a recursive glob
At 2 vs. 4 chars (or 3 vs. 6 keydowns) it
may not *look* much briefer, but it feels
much easier to type once you're used to it.
4) On the fly command line colorization along
the lines of zsh-syntax-highlighting.
Spot syntax errors/missing cmds *before*
you hit <ENTER>.
5) vared MyVar
Use the ZLE to easily modify any evar.
6) Zsh's REPORTTIME
*automatically* report time/memory of only
"expensive" programs/pipelines.
7) Zsh's extended history format that includes
both the time started as well as *duration*
of all my commands.
8) Floating point arithmetic and $[]
forget all this calculator jazz. I just
do `alias ec=echo` and go `ec $[1234./56]`
or even just : $[1234./56]<TAB>
9) glob qualifiers (forget `find` or `fd`)
My main use cases are *(.) *(@) & *(/),
sometimes with a ^ for "not" in there,
e.g. *(^/). The codes are mostly the
old ls -F codes to be easy to recall.
If anyone knows how to make Bash do any of those, I would appreciate the tip. Otherwise, maybe they count as "killer" features to someone.
Also, I tend to use a global alias "/n" for "/dev/null". I know I could just use $n with n=/dev/null, but I enjoy having it look like a path in / that never actually exists.
Not sure why you are getting all zeros in your duration column. Should be setopt ExtendedHistory (Zsh setopts, like Nim identifiers, are "style insensitive").
From the Zsh man page:
EXTENDED_HISTORY <C>
Save each command's beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. The format of this prefixed data is:
`: <beginning time>:<elapsed seconds>;<command>'.
(EDIT: My best guess explanation is some competing/conflicting setopt, but the Zsh mailing list could almost surely help you. Also, `history -fD` may show the correct answer even if the saved file has all 0s.)
Thank you! How strange. `history -fD` does work, but only for commands in the current zsh session. It seems durations are being stored in memory but written out as 0's. I'll try the mailing list soon :)
In my case, I have INC_APPEND_HISTORY enabled. It appears I get 0 in the duration column because it's writing to the history file before executing the command. I see there's the alternative option INC_APPEND_HISTORY_TIME to append to history after the command finishes in order to include the duration.
It makes sense. It's preferring to add to history immediately so that it's available to other shells without having to wait for the command to finish.
From the manpage:
> INC_APPEND_HISTORY_TIME This option is a variant of INC_APPEND_HISTORY in which, where possible, the history entry is written out to the file after the command is finished, so that the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY for‐ mat. This means that the history entry will not be available immediately from other instances of the shell that are using the same history file. This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive.
Hah. @jolmg & I almost collided to the second. :-) That stackexchange link had an answer with the INC_APPEND_HISTORY_TIME setopt which seems to work without SHARE_HISTORY (I think using his whole stackexchange answer might still result in 0s..at least it did for me when I ran it in a precmd() instead of adding the hook, but it could always be something else varying between his & my setopts).
Read this thread [1] at the Zsh mailing list to the end.
It looks like either share_history or inc_append_history break recording duration in a fundamental way. The TL;DR is that the history line is written out before the command in question completes. I guess the thinking is that inc/shared history with some very long running command is not as useful if you wait until it ends and you have elapsed time data to append that line. I feel like that might be a personal issue - like if you almost only ever run commands 1-90 seconds then you are fine with the delay.
Anyway, this also explains why it is available from the `history -fD` command but not in the file.
I use aliases, too. But an alias for every possible "bookmarked" directory seems excessive. Like this guy [1] in the current thread, I tend to just say x=`pwd` (no need to always `export`). Agreed there is probably a way to set up a shell function `a() {...}` that establishes an alias (or even a shell function) almost as simply, but another problem that remains is that aliases and variables are separate namespaces. So, if you do it the variable way like Zsh then you don't have to worry about clobbering some existing alias or shell function. You do have to keep these separated namespaces in your head, but the updating of the prompt to the variable name is a pretty good reinforcement cue (at least for me, in practice). Also, the variable lets you use it in composed paths like `$x/bin/foo` while an alias/function would only change your directory.
TL;DR - Yuck = namespace squishing in this application only, but then again one man's "collapse of namespaces being yucky" is another's "yay, I do not have to remember 3..4 namespaces!".
EDIT: for what it's worth, I never intended my 9..11 items to be "in order of importance or persuasiveness". Mostly in order of personally driving me batty when I use Bash and just meant to actually be things Zsh could do that (present)Bash could not, to my knowledge due to @deadbunny's complaint. I do try to keep a side Bash config that is as close as possible to my Zsh config, because it's not always worth my time to compile/install Zsh on a system. But when I do that and start using Bash, I notice all these missing things. { That's why I would genuinely appreciate anyone who knows how to replicate them in Bash saying how. I'm not just "daring the Bash apologists to a challenge" or whatever. :-) }
9 goes quite far. My most common uses are downloads/*(oc[1]) for the latest downloaded file (order by time of inode change and return just first result), or downloads/*(c0) for all the files downloaded today (created 0 days ago in downloads directory).
10) =() expansion. It's like <() which both bash and zsh have, but instead of substituting with the path to a pipe, it substitutes with the path to a temporary regular file. Sometimes pipes don't suffice. For example, I can do `viewnior =(maim -s)` to select a region of the screen and see it in an image viewer immediately. `viewnior <(maim -s)` fails because viewnior can't display an image from a pipe.
11) short syntax for control structures. For example, you can do `for x in $(xs); foo $x` without bothering with `do` and `done`.
12) variable expansion in brace expansion. In bash, `x=5; echo {3..$x}` outputs `{3..5}`. zsh outputs `3 4 5`.
13) Command can be just redirection without any executable. `<<< foo` is equivalent to `cat <<< foo`, `> foo.txt` is equivalent to `cat > foo.txt`.
14) Able to convert numbers between any bases. To convert base-5 10 to base-4: `<<< $(( [#4] 5#10 ))` outputs `4#11` which means 11 in base-4.
15) Named directories. I have my project files organized under deep directories like ~/work-for/.../.../.../foo/, and have configured all those as named directories to be able to access them as `~foo`, for instance. Different from using simple variables for this, named directories are compacted when presented by the shell. So in my prompt, I see my current directory is e.g. `~foo/bar` instead of the whole thing from the home dir. Named directories come in 2 forms, static and dynamic. Static named dirs are when you set them up in a hash of name => directory. Dynamic named dirs are when you define a function that expands arbitrary names to paths and compacts arbitrary paths to names.
16) `=foo` expands to the full path of executable foo. So you can, e.g. see the source of `pass` with `less =pass`.
17) Variable expansion syntax, glob qualifiers, and history modifiers can be combined/nested quite nicely. For example, this outputs all the commands available from $PATH: `echo ${~${path/%/\/*(*N:t)}}`. `${~foo}` is to enable glob expansion on the result of foo. `${foo/%/bar}` substitutes the end of the result of foo to "bar" (i.e. it appends it); when foo is an array, it does it for each element. In `/*(*N:t)`, we're adding the slash and star to the paths from `$path`, then the parentheses are glob qualifiers. `*` inside means only match the executables, `N` is to activate NULL_GLOB for the match so that we don't get errors for globs that didn't match anything, `:t` is a history mod used for globs that returns just the "tail" of the result, i.e. the basename. IIRC, bash can't even nest multiple parameter expansions; you need to save each step separately.
18) Suffix aliases can be used to define how to open arbitrary files. `./foo.mp4` opens it up in with `mpv`, because I have `alias -s mp4=mpv`.
19) Global aliases are useful for expanding stuff anywhere. For example, I have `alias -g %LD='~/downloads/*(oc[1])'` so that `%LD` expands to the latest download as part of any argument to a command.
20) Globbing flags. There are various flags for globbing, that enable e.g. backreferences in globs, allow n-number of errors while matching (approximate matching), etc. The only one I've really used though is `i` which enables a glob to be case-insensitive. So `(#i)*.pdf` matches `foo.pdf` as well as `bar.PDF`.
21) Multios. You can use multiple files in individual redirections. For example, `foo > bar | baz` is equivalent to `foo | tee bar | baz`. That accepts globbing and brace expansion too: `foo > *.{c,h}` is the same as `foo | tee *.{c,h}`. Also works for reading: `foo < *.txt` is practically the same as `cat *.txt | foo`. I must...
If I did that & something for bash that used awk | python to do FP arithmetic I might be able to evolve to a more "portable habit/muscle memory" even if Bash never learns FP arithmetic. Solid suggestion, @tux1968. Thanks. { EDIT: 1 down, a dozen to go! lol :-) and I'll go with a(){..} for a)rithmetic not c since I use that for clear. }
While I agree that these are not killer features, I'd suggest reading more about zsh. It's not meant to "replace" bash. It's meant to be easily extensible (addons, etc.) The target is folks that stay from bash scripting.
7. in bash, I use the: [Esc], [#] combo, equivalent to: [Alt]-[Shift]-[3] (a.k.a.: "M-#" in the official docs).
This is a shortcut which basically prefixes the current line with '#' comment character and then simulates hitting Enter (pushing the commented-out line into history buffer).
Re 1., if you put a -p on the mkdir it becomes a bit more powerful.
I've had equivalents of that command going back to DOS batch files on a 286. I've always called it "ad", for "add directory" (though I'll concede that's mainly a good name because it's short).
The one thing I really don’t want to live without is “intellisense” that changes the default input to a prefix-search that ghosts the top result ahead of your typing.
The feature was stolen from fish it’s 100% worth it to me.
Pressing `!` in the target directory will open a new terminal
session within nnn, with that path as working dir. When you
`exit` you'll land in nnn again.
It's not exactly the same but close enough for me.
That will cd to the selected file's directory with enter/right, or do nothing if you simply quit. I guess it depends if you use it for browsing a lot or simply picking a file.
I wouldn't be surprised if this was coerced by the marketing department, trying to imbue that "ooh, look at me, I'm a bit crazy, so creative" vibe for a bloody shopping list.
I have no comments about this particular font. But if your marketing department has any say in your terminal fonts, you should quit this creepy place as soon as possible!
see, the kerning is fine on that though. its not my taste, but it works. This article looks like either something is just wrong with the font, or letterspace needs to be adjusted in the terminal's config.
I just recently ditched oh-my-zsh as I wanted to understand and have more control over my shell. I have to say that just using native zsh capabilities I don't miss oh-my-zsh at all.
If you're looking to go full rabbit hole, the zsh native scripting handbook is good for a few examples. Easy to end up in linenoise if you're not careful though. A fair few really nice zsh things in zdharma's GitHub repos too.
I've been using Fish instead and it's much much simpler than configuring ZSH to my liking. It's already good out of the box, without having to carry around any kind of configuration. The only stuff I usually do is to setup `powerline-go` as prompt, and voilà, that's pretty much it.
The main drawback for fish is that is not compatible with bash scripting. If you need help with something specific, you can throw out almost all help available online.
I am a happy Fish user, too. The first downside that comes to my head is that if you want to share a script you wrote that you have to translate it to bash first. Much less of an issue if you're using zsh.
I'm a zsh user, and I disagree on it not being much of an issue. It is very easy to inadvertently rely on all manner of zsh-specific behaviour in scripts. Short form logic syntax, builtins with different arguments, internal stat/attr/datetime/etc manipulation, my personal favourite $RANDOM behaves differently to bash in subshells, and much more.
zsh does have the emulate builtin available to help with some basic things, but it is still easy to produce scripts littered with zsh'isms.
However, I do use zsh for personal scripts. In fact, I go so heavy on zsh'isms I know I'd need to rewrite things to share them if non-zsh users are an issue. It is easier to keep track of things that way, instead of tripping over the little easily forgotten quirks.
I rather liked Fish's zero config approach but I found their handling of the PATH very hard to work with day to day. Perhaps it was just my familiarity with having a bunch of statements to alter the PATH in a config file but it felt very opaque, I always had to look up how to add stuff to the PATH and I had great trouble trying to remove stuff from the PATH.
I LOVE the way fish handles PATH. I just modify the $fish_user_paths variable (which is a universal variable) and I don’t have to modify any config files.
E.g. to permanently add `~/.cargo/bin/` to your PATH just do
Salty/sweet contrast is the core of Hawaiian pizza appeal, and flavour/texture contrasts are the foundation of some of the most interesting foods, for instance salted caramel, pork and apples, etc.
Using fzf and ctrl+r for fuzzy finding commands is a godsend.
Basically all snippets of code that I ever run are straight from this.
Forget how to exactly reset a committed local file that you want to place into another commit? Not something I do everyday, so may require some Googling if I can't remember exactly.
What I do know, is that I use something with `git reset`.
I ctrl+r and type `git reset` and here is what comes up:
> 9488 git reset HEAD^
> 10535* git reset --hard
> 10555* git reset HEAD file
> 10999* git reset --soft HEAD
Oh right, I need to reset the commits and then remove that file from the commit and I can recommit.
Direnv has made it a lot easier to source Bash-styled environment variable in a fisd shell and has `use nix` built in for using the Nix package manager for projects and getting a shell environment with all of your local project dependencies.
Pretty clickbaity title. Nothing "mind blowing" about what's in that article really. I used to use Zsh but switched back to bash a few years ago because most of the things I liked in Zsh turned out to be doable in Bash and I just didn't look enough.
I personally don't think the typography in the page itself is bad, it's the screenshots (and indeed their color schemes and types) and the lack of vertical rhythm of the whole thing that pose the biggest problems.
217 comments
[ 3.0 ms ] story [ 239 ms ] threadI'm not sure why this isn't a part of zsh already, but if you want to see the last few commands you ran in the current directory, that little utility will do that for you. Great for reminding yourself what you did last time you were in a directory.
Then again, cut would do the same thing anyway.
Sometimes it’s well executed (see Realm’s) sometimes it’s not.
Is there something I'm missing, like a good default .zshrc?
Apple really doesn’t like GPL 3.
https://wiki.archlinux.org/index.php/Zsh#Command_completion
Has that changed?
It's a shame they can't do these things asyncronously or cache them.
Turns out my main issue was due to having a slow node --version command due to using asdf!
This project was a huge help: https://github.com/danhper/asdf-exec
This is very powerful in large git repos etc. You're never waiting for the prompt. You just type immediately, w/immediate response. So, you only wait for the status information to show up when you need it. So you also don't pay an excessive penalty if you prefer overly chatty prompts.
AFAICT the lazy-loading and async-support tickets above talk about internal implementation details, timeout support (so cancelling stuff like a too slow status report and showing a simplified prompt). I may misunderstand that, I only gave it a quick glance.
Maybe starship already supports this for zsh, or not, but at least they don't promote it front and center.
Instead you can have a 1-letter command to print out a slew of useful info only when you want.
https://github.com/romkatv/zsh4humans
[1]: https://ohmyz.sh/
1. `mkcdir () { mkdir -- "$1" && cd -- "$1"; }`
2a. `bind '"\e[A":history-search-backward'; bind '"\e[B":history-search-forward'`
2b. Default behavior for Bash.
3. `shopt -s autocd`
4. `mmv`, `perl-rename`
5. `qalc` from libqalculate: https://github.com/Qalculate/libqalculate
8. Default behavior for Bash.
9. Default behavior for Bash.
Or, you know, any REPL available.
Just a little shortcut but REPLs like Python's take a while to spin up, so it's pretty convenient.
Maybe without lower scale and with the semicolon:
"Stealing" the equals sign for this purpose feels a bit risky, but maybe it isn't.To that point zsh has some excellent additions for process substitution beyond bash's <(list), but it also makes for yet more weird incompatibilities for when that matters. I only looked at this to start with because I assumed the space was because =() would have been treated as the full path modifier for a command called (), because it would mean that with any other character including other bracket types. TIL.
Really? Loading python takes basically 0 seconds for me... the slowest I could get running `time python3` and hitting ctrl-d (to exit) is like 0m0.104s.
7. C-a C-k <enter other command> C-y # to park a command
(since it invokes your editor, and you can configure it to be emacs)
The features need to be able to do useful things better somehow, and that's where articles demoing such applications come in.
"Better" also doesn't necessarily mean "more concise," otherwise APL would be one of the best programming languages. A language with a smaller number of accessible, comprehensible, memorable features can prove more useful in practice than one with a "dizzying assortment" that's hard to remember, difficult to read, etc.
I noted down the things I thought would be useful day-to-day, and started using them. A few months later, I skimmed through the manual again. I still do so, every year or two. My work gradually changes, and I find Zsh has features that are now useful to me.
This is the suggested manpage: https://linux.die.net/man/1/zshexpn
The issue is how to decide whether something is worth looking at.
An article which gives examples that can easily be achieved by some more mainstream system is unconvincing. That's what was being discussed here:
> This is always my complaint about posts like this. I read them looking for the killer feature to make me consider switching from bash and it's always stuff bash does natively or with a one line alias.
> This is the suggested manpage: https://linux.die.net/man/1/zshexpn
Yes, the comment I replied to already suggested that. You're not doing much to convince me that your judgment is worth respecting.
Global aliases (interpolated anywhere in the commandline)
Replace on the fly long directory names with short paths All the tweaks to ignore dups in the history, when saving/searching.Do you know why "bash does [these things] natively"? Because zsh had them 20 years ago when bash was barebones and people were envious and over time bash started copying these features over. Sometimes poorly.
And for the "one line alias", in a bunch of cases it's with additional commands, which are not always available, the most famous example being rename.
Which rename? The binutils one (I think) or the Perl one (which has more features)?
Does your distro even package both?
Things can be a lot more complex than they seem.
While Bash has "caught up" some in the ensuing decades by copying features (some poorly as you note), I think it still misses quite a few nice "usability" features. I've listed some here [1] from memory, but I am probably forgetting other pretty nice ones. Like maybe ${(f)"$(mycmd)"} to split the output of `mycmd` strictly by newlines. (or ps:\0: for even stricter splitting).
[1] https://news.ycombinator.com/item?id=26176897
Also, I tend to use a global alias "/n" for "/dev/null". I know I could just use $n with n=/dev/null, but I enjoy having it look like a path in / that never actually exists.
Woah, how do I enable this? From what I can tell this information is not being stored in $HISTFILE:
From the Zsh man page:
EXTENDED_HISTORY <C> Save each command's beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. The format of this prefixed data is: `: <beginning time>:<elapsed seconds>;<command>'.
(EDIT: My best guess explanation is some competing/conflicting setopt, but the Zsh mailing list could almost surely help you. Also, `history -fD` may show the correct answer even if the saved file has all 0s.)
[1] https://unix.stackexchange.com/questions/396809/zsh-share-hi...
It makes sense. It's preferring to add to history immediately so that it's available to other shells without having to wait for the command to finish.
From the manpage:
> INC_APPEND_HISTORY_TIME This option is a variant of INC_APPEND_HISTORY in which, where possible, the history entry is written out to the file after the command is finished, so that the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY for‐ mat. This means that the history entry will not be available immediately from other instances of the shell that are using the same history file. This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive.
It looks like either share_history or inc_append_history break recording duration in a fundamental way. The TL;DR is that the history line is written out before the command in question completes. I guess the thinking is that inc/shared history with some very long running command is not as useful if you wait until it ends and you have elapsed time data to append that line. I feel like that might be a personal issue - like if you almost only ever run commands 1-90 seconds then you are fine with the delay.
Anyway, this also explains why it is available from the `history -fD` command but not in the file.
[1] https://www.zsh.org/mla/workers/2011/msg01297.html
TL;DR - Yuck = namespace squishing in this application only, but then again one man's "collapse of namespaces being yucky" is another's "yay, I do not have to remember 3..4 namespaces!".
EDIT: for what it's worth, I never intended my 9..11 items to be "in order of importance or persuasiveness". Mostly in order of personally driving me batty when I use Bash and just meant to actually be things Zsh could do that (present)Bash could not, to my knowledge due to @deadbunny's complaint. I do try to keep a side Bash config that is as close as possible to my Zsh config, because it's not always worth my time to compile/install Zsh on a system. But when I do that and start using Bash, I notice all these missing things. { That's why I would genuinely appreciate anyone who knows how to replicate them in Bash saying how. I'm not just "daring the Bash apologists to a challenge" or whatever. :-) }
[1] https://news.ycombinator.com/item?id=26177537
10) =() expansion. It's like <() which both bash and zsh have, but instead of substituting with the path to a pipe, it substitutes with the path to a temporary regular file. Sometimes pipes don't suffice. For example, I can do `viewnior =(maim -s)` to select a region of the screen and see it in an image viewer immediately. `viewnior <(maim -s)` fails because viewnior can't display an image from a pipe.
11) short syntax for control structures. For example, you can do `for x in $(xs); foo $x` without bothering with `do` and `done`.
12) variable expansion in brace expansion. In bash, `x=5; echo {3..$x}` outputs `{3..5}`. zsh outputs `3 4 5`.
13) Command can be just redirection without any executable. `<<< foo` is equivalent to `cat <<< foo`, `> foo.txt` is equivalent to `cat > foo.txt`.
14) Able to convert numbers between any bases. To convert base-5 10 to base-4: `<<< $(( [#4] 5#10 ))` outputs `4#11` which means 11 in base-4.
15) Named directories. I have my project files organized under deep directories like ~/work-for/.../.../.../foo/, and have configured all those as named directories to be able to access them as `~foo`, for instance. Different from using simple variables for this, named directories are compacted when presented by the shell. So in my prompt, I see my current directory is e.g. `~foo/bar` instead of the whole thing from the home dir. Named directories come in 2 forms, static and dynamic. Static named dirs are when you set them up in a hash of name => directory. Dynamic named dirs are when you define a function that expands arbitrary names to paths and compacts arbitrary paths to names.
16) `=foo` expands to the full path of executable foo. So you can, e.g. see the source of `pass` with `less =pass`.
17) Variable expansion syntax, glob qualifiers, and history modifiers can be combined/nested quite nicely. For example, this outputs all the commands available from $PATH: `echo ${~${path/%/\/*(*N:t)}}`. `${~foo}` is to enable glob expansion on the result of foo. `${foo/%/bar}` substitutes the end of the result of foo to "bar" (i.e. it appends it); when foo is an array, it does it for each element. In `/*(*N:t)`, we're adding the slash and star to the paths from `$path`, then the parentheses are glob qualifiers. `*` inside means only match the executables, `N` is to activate NULL_GLOB for the match so that we don't get errors for globs that didn't match anything, `:t` is a history mod used for globs that returns just the "tail" of the result, i.e. the basename. IIRC, bash can't even nest multiple parameter expansions; you need to save each step separately.
18) Suffix aliases can be used to define how to open arbitrary files. `./foo.mp4` opens it up in with `mpv`, because I have `alias -s mp4=mpv`.
19) Global aliases are useful for expanding stuff anywhere. For example, I have `alias -g %LD='~/downloads/*(oc[1])'` so that `%LD` expands to the latest download as part of any argument to a command.
20) Globbing flags. There are various flags for globbing, that enable e.g. backreferences in globs, allow n-number of errors while matching (approximate matching), etc. The only one I've really used though is `i` which enables a glob to be case-insensitive. So `(#i)*.pdf` matches `foo.pdf` as well as `bar.PDF`.
21) Multios. You can use multiple files in individual redirections. For example, `foo > bar | baz` is equivalent to `foo | tee bar | baz`. That accepts globbing and brace expansion too: `foo > *.{c,h}` is the same as `foo | tee *.{c,h}`. Also works for reading: `foo < *.txt` is practically the same as `cat *.txt | foo`. I must...
This is a shortcut which basically prefixes the current line with '#' comment character and then simulates hitting Enter (pushing the commented-out line into history buffer).
I didn't have this on my system. I like the article because this was a command I've needed many times without realizing it.
https://www.nongnu.org/renameutils/
The feature was stolen from fish it’s 100% worth it to me.
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....
If you like terminal productivity I recommend: fzf, Facebook path picker (aka fpp), fd, ripgrep, lf, tig.
Some honorable mentions: tokei, hyperfine, lazydocker, ctop, ncspot.
lf is also fast but has ranger's look and feel.
It's not exactly the same but close enough for me.
I'd prefer something like:
That will cd to the selected file's directory with enter/right, or do nothing if you simply quit. I guess it depends if you use it for browsing a lot or simply picking a file.Plus any project from sharkdp and burntsushi and any tools recommended by Brendan Gregg.
ht editor is a personal favorite too (press F6 and go to image to get started).
seems so. recently discussed: https://news.ycombinator.com/item?id=25520510 https://dtinth.github.io/comic-mono-font/
http://www.comicneue.com/
A good guide (although a bit old and maybe too thick :) ) is this one: http://zsh.sourceforge.net/Guide/zshguide.pdf
https://zdharma.org/Zsh-100-Commits-Club/Zsh-Native-Scriptin...
E.g. ctrl-l and ctrl-r
I'd like a way to get all the benefits without the cost or any extra required effort for the user.
Some painless master shell program. No epiphanies yet though.
Do you know what I do?
I use zsh. Let's say I need bash. "bash<Enter>". I'm in bash :-) I need cmd (yup, that can happen). "cmd<Enter>".
I need to run just one command with bash: "bash command<Enter>".
I need to run just one command with cmd: "cmd /c command<Enter>".
These problems are trivially solvable :-)
Aliases and macros are fish script though.
zsh does have the emulate builtin available to help with some basic things, but it is still easy to produce scripts littered with zsh'isms.
However, I do use zsh for personal scripts. In fact, I go so heavy on zsh'isms I know I'd need to rewrite things to share them if non-zsh users are an issue. It is easier to keep track of things that way, instead of tripping over the little easily forgotten quirks.
E.g. to permanently add `~/.cargo/bin/` to your PATH just do
once from an interactive shell, and you’re done![1] https://github.com/starship/starship
Whenever the local Italian restaurant opens back up I'll go and try a properly made Hawaiian pizza :)
This is especially true for tomato, which unless very sweet and acidic like in sticky sauce, it doesn't go well at all with pineapple.
Not ZSH specific, but it's also handy to load project-specific environment variables automatically on entering directories: https://direnv.net/.
[0] https://github.com/junegunn/fzf
Basically all snippets of code that I ever run are straight from this.
Forget how to exactly reset a committed local file that you want to place into another commit? Not something I do everyday, so may require some Googling if I can't remember exactly.
What I do know, is that I use something with `git reset`.
I ctrl+r and type `git reset` and here is what comes up:
> 9488 git reset HEAD^
> 10535* git reset --hard
> 10555* git reset HEAD file
> 10999* git reset --soft HEAD
Oh right, I need to reset the commits and then remove that file from the commit and I can recommit.
It is a complete gamechanger.
or as recently discussed Comic Mono: https://news.ycombinator.com/item?id=25520510 https://dtinth.github.io/comic-mono-font/
Jeez, this is great!