Fixing macOS Zsh Terminal History Settings
41–50 of 66 posts
Re: Fixing macOS Zsh Terminal History Settings
#42This is zsh specific, but here's something I've been burned by enough times that I specifically wanted to mention it: save your history in a file other than the default one. Why? Because if you increase the history limit, and your profile isn't sourced for any reason, the shell will read your history file and use the default history size, clobbering everything that's there. If you use a non-default history file this…
Re: Fixing macOS Zsh Terminal History Settings
#43I often have multiple concurrent sessions of terminal open, which leads to messed up history interactions. One solution I've encountered (but have not tested yet) is zsh-histdb [0]. It stores sessions' history to a SQLite db instead of a single appended file, with extra metadata about when commands were run, what session, etc. If you've already got your .zshrc file open to mess with the history settings it might be w…
Storing history in SQLite is such a wonderful idea, I wonder why someone doesn’t just add it to readline/libedit/etc, then all apps (which use those libraries) can do it. Although, I wonder if that might cause problems, if apps already link to SQLite and they might expect a different version, or if unstable apps might cause concurrency/corruption/etc issues with a shared per-user history DB. To avoid all that, maybe…
sqlite-utils create-table ~/commands.db commands id integer text text --pk id
PROMPT_COMMAND="( fc -n -l -1 | perl -p -e 's/^\s+//; chomp if eof' | sqlite-utils insert --text ~/commands.db commands - & )"
It's slow, has perl & python external deps, needs a timestamp column, call subshell to avoid job control messages, ...A nicer single "prompt command" wrapper is certainly possible though.
Re: Fixing macOS Zsh Terminal History Settings
#44This is zsh specific, but here's something I've been burned by enough times that I specifically wanted to mention it: save your history in a file other than the default one. Why? Because if you increase the history limit, and your profile isn't sourced for any reason, the shell will read your history file and use the default history size, clobbering everything that's there. If you use a non-default history file this…
I got burned a couple of times in the past with bash-history, and go a small step beyond this, even on zsh, and added to .zshrc: preexec_custom_history() { echo "$HOSTNAME $$ $(date "+%Y-%m-%dT%H:%M:%S%z") $1" >> "~/.fullhistory" } preexec_functions+=(preexec_custom_history) I work on a lot of shared-filesystem computers, and so it's useful to be able to filter for commands ~year ago when I know what computer I was o…
How does the history know that the prefix (hostname, PID, date) is not part of the command though?
I mean, I tested it and it works as expected (without them) but I'm really curious about how it works.
Re: Fixing macOS Zsh Terminal History Settings
#45OT but the first command I type on a new install of MacOS is $ chsh -s /bin/bash because I have 20 years worth of bash scripts that I've carefully tailored to work on bash in MacOS and Linux and I don't have time to rewrite them all just because Apple decided they don't like GPLv3.
Before they changed the default the first command I had to type on a new install was $ chsh -s /bin/zsh You can’t please everybody.
Re: Fixing macOS Zsh Terminal History Settings
#46Earlier quoted context omitted.
I got burned a couple of times in the past with bash-history, and go a small step beyond this, even on zsh, and added to .zshrc: preexec_custom_history() { echo "$HOSTNAME $$ $(date "+%Y-%m-%dT%H:%M:%S%z") $1" >> "~/.fullhistory" } preexec_functions+=(preexec_custom_history) I work on a lot of shared-filesystem computers, and so it's useful to be able to filter for commands ~year ago when I know what computer I was o…
Thanks, this looks great! How does the history know that the prefix (hostname, PID, date) is not part of the command though? I mean, I tested it and it works as expected (without them) but I'm really curious about how it works.
Re: Fixing macOS Zsh Terminal History Settings
#47Earlier quoted context omitted.
Before they changed the default the first command I had to type on a new install was $ chsh -s /bin/zsh You can’t please everybody.
I recommend first installing a recent bash from macports, update /etc/shells first; then change to /opt/local/bin/bash. Unless you enjoy using an ancient bash.
Re: Fixing macOS Zsh Terminal History Settings
#48This is zsh specific, but here's something I've been burned by enough times that I specifically wanted to mention it: save your history in a file other than the default one. Why? Because if you increase the history limit, and your profile isn't sourced for any reason, the shell will read your history file and use the default history size, clobbering everything that's there. If you use a non-default history file this…
Also I don't understand why modern shells are so conservative about the defaults. I understand that if a single history file is large, it might slow down shell startup and operation, but at the very least shells could/should do periodic history file rotation. It's very very very unlikely that the history files will be eating all the disk space.
There can be other reasons for wanting a smallish history besides fast startup like wanting low history numbers if you learnt all the ancient `!` history escapes that were the main way of using history with csh going back forty-plus years ago. This is also one of the reasons why extension theme frameworks like oh-my-zsh have become popular - much of what they do is enable bells and whistles that are features of the core shell.
Re: Fixing macOS Zsh Terminal History Settings
#49Does someone knows of some config to make zsh behave similar to bash for interactive use?
So don't try to make zsh mimic bash, use it as-is and whenever something bothers you, try to understand both how the behaviour can be changed and consider the actual merit of the options.
Re: Fixing macOS Zsh Terminal History Settings
#50Earlier quoted context omitted.
I recommend first installing a recent bash from macports, update /etc/shells first; then change to /opt/local/bin/bash. Unless you enjoy using an ancient bash.
Wtf, macports ? Please do your self a favor and install Nix package manager.
I'm also sad that pkgsrc seems to be abandoned wrt binary builds for macos - I could at least not find correct gpg keys for verifying the archives listed at: https://pkgsrc.joyent.com/install-on-macos/
Perhaps it's workable as a build-from-source package manager.
For now, it seems that macports have most of what I need - with less complexity than nix, and a better handling of upgrades than brew.
Does appear that brew moves faster, eg: https://trac.macports.org/ticket/65922 (i briefly tried a local build, but ran into dependency problems with libvterm that I didn't manage to resolve - there's a 0.3 [2] tarball, but the build system for neovim wasn't happy and kept finding 0.1.4 after it was uninstalled in favour of 0.3).
[1] https://nixos.org/manual/nix/stable/installation/installing-...