Live data from Hacker News

Zsh Tricks to Blow Your Mind

twilio.com

171–180 of 218 posts

Re: Zsh Tricks to Blow Your Mind

#171
Never use sudo with `npm install` as was done in example 6.

I know it's off topic, but it would be good if the author could change that example. In general, one should never use sudo with package managers.

Re: Zsh Tricks to Blow Your Mind

#172
Funny, like the author I also have a 'desktop not icloud' folder but I just call it 'scratch'

If you opt-in to the iCloud personal folder mirroring feature it will move your Desktop folder into the cloud. This gets kinda troublesome if you are the kind of person who uses your desktop as a scratch space for random crap.

I now have a ~/scratch folder for this. I also added a ~/screenshots folder and used the app Onyx to change where macOS saves screenshots.

Now I get the best of both worlds.

Re: Zsh Tricks to Blow Your Mind

#174

> Ctrl-q "parks" the command What is the zsh functionality behind this? I couldn't test it because my terminal eats Ctrl-q and a search for "zsh ctrl-q" didn't turn up anything useful.

Alternatively, you could use vi mode with 'bindkey -v'. Then you could use 'dd'/'cc' and 'p' to achieve the same thing.

Re: Zsh Tricks to Blow Your Mind

#175
post #158

Earlier quoted context omitted.

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 :)

Looks like you probably also have SHARE_HISTORY set? [1] [1] https://unix.stackexchange.com/questions/396809/zsh-share-hi...

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.

Re: Zsh Tricks to Blow Your Mind

#176
post #152

Earlier quoted context omitted.

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 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: `: : ; '. (EDIT: My best guess explanation is some competing/con…

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 :)

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.

[1] https://www.zsh.org/mla/workers/2011/msg01297.html

Re: Zsh Tricks to Blow Your Mind

#179
post #175
post #158

Earlier quoted context omitted.

Looks like you probably also have SHARE_HISTORY set? [1] [1] https://unix.stackexchange.com/questions/396809/zsh-share-hi...

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 t…

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).

Re: Zsh Tricks to Blow Your Mind

#180
The fatuous use of animated images to illustrate the wonders of a tool that is fundamentally text/character based is (ahem!) puzzling, considering that those most likely to be interested are also those most likely to wish they could do simple Cut/Paste of the examples for experimentation, now difficult or impossible because of all the glitz....
Post reply on HN