setopt listambiguous not setting the option - zsh

In ZSH I run this at the command line:
$ setopt listambiguous
I then run setopt to get a list of current options:
$ setopt
It's not in the list. Why not?

The list_ambiguous option is on by default, so setopt listambiguous changes nothing unless you've previously turned it off. A plain setopt doesn't display options whose setting is the default value.

Related

Why is `print -P "%%"` behaviour different within library function?

On my terminal:
$ print -P "%%"
%
The equivalent code within a Spaceship prompt function:
spaceship_extension() {
unset PROMPT_PERCENT
unset PROMPT_SUBST
print -P "00%%\n"
set PROMPT_PERCENT
unset PROMPT_SUBST
print -P "01%%\n"
unset PROMPT_PERCENT
set PROMPT_SUBST
print -P "10%%\n"
set PROMPT_PERCENT
set PROMPT_SUBST
print -P "11%%\n"
}
Output:
00
01
10
11
According to the Prompt Expansion man page, those are the only relevant environment variables. Does anyone have any idea what's going on here?
Edit: Removed exports that were obviating the setting and resetting of the environment variables.
First problem is that export has no effect on either option; you are just setting the export attribute on a set of names in each case.
Second, set and unset operate on names, not shell options. You want setopt and unsetopt.
% setopt PROMPT_PERCENT
% print -P '00%%\n'
00%
% unsetopt PROMPT_PERCENT
% print -P '00%%\n'
00%%
(In practice, unsetting PROMPT_PERCENT may affect your actual prompt; I used % here as a placeholder for the prompt, not an accurate representation of what you prompt may look like after unsetting the option.)

What can I change in order that Compdef can bind my function?

I have created some console commands in PHP. I need to use autocompletion when I launch my tasks.
I used alias otra="php console.php" in my .zshrc file.
The function itself seems to work but when I type my command name 'otra', there is only folders autocompletion...which is completely irrelevant in my case.
#compdef _otra otra
function _otra {
local line
_arguments -C \
"1: :(createAction createBundle)" \
"*::arg:->args"
}
I want to only have the two words createAction and createBundle to appear when I type otra and type .
EDIT
Ok, it is what I was thinking...if I remove my alias, the completion works but I cannot remove it since otra is not a valid command...
I tried to use setopt no_complete_aliases as I see it in another Stackoverflow post but it does not work for me.
In fact, it was related to the alias but I did not have to set setopt no_complete_aliasesin my case but pretty much the contrary...
After I put setopt complete_aliases in my .zshrc file, it works :D

zsh ignores SAVEHIST size

Today I made the switch from bash to zsh (+ oh-my-zsh) on my Mac. In bash I kept an .bash_eternal_history with over 30k entries. I migrated that into the .zsh_history file and format.
Now I set these vars to keep an eternal history in zsh (taken from [1]):
HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000000
SAVEHIST=10000000
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.
[1] https://unix.stackexchange.com/a/273863
But the number in SAVEHIST get's ignored. No matter how high I set it, when I type echo $SAVEHIST in my shell, I get 10,000 and my .zsh_history file with over 30k entries gets capped at 10,000
What am I missing?
add $SAVEHIST and other hist parameters at the end of .zshrc.
(some oh-my-zsh bug)
it helps https://www.reddit.com/r/zsh/comments/f29hn4/omz_is_this_a_bug_in_historyzsh/fhf822j
I moved this section from .zshrc to ~/opts/args.sh, and in .zshrc I added the line source ~/opts/args.sh. That solved it

Disable Zsh history completely

I would like to disable Zsh history (arrow up) and zle history search (namely esc+p) completely. How can I achieve this?
My current .zshrc:
unsetopt hist_append
unsetopt hist_expand
HISTFILE=
HISTSIZE=SAVEHIST=0
Currently I have history buffer of one, but I'd like to have history of zero.
21-10-2016 Update:
I've added
bindkey -r "^[p"
bindkey -r "^Xr"
bindkey -r "^Xs"
bindkey -r "^[[A"
bindkey -r "^[[B"
bindkey -r "^[n"
to get rid of history features that I use (esc+p is deeply hardwired to my backbone - so difficult to unlearn).
I don't see anything in the zsh man page that completely disables history. Even setting HISTSIZE=0 seems to reset the value of HISTSIZE to 1.
You'll probably have better luck changing the key bindings with bindkey so that history features never occur. For example, bindkey -r "^[[A" for my up-arrow key (note that I actually typed a caret and two brackets, not an escape key).
I use following entries in my .zshrc:
alias disablehistory="function zshaddhistory() { return 1 }"
If function zshaddhistory is defined, it can control whether history line will be saved.
Therefore, alias disablehistory will just define function that always returns 1 (don't save).
alias disablehistory="function zshaddhistory() { return 1 }"
alias enablehistory="unset -f zshaddhistory"
enablehistory just unsets function set by previous alias.
If you want to disable history completely, permanently define zshaddhistory in your .zshrc
Try configuring your ZSH setup to run a postexec function that empties/deletes your .zhistory file. It's a hacky workaround but should probably work.

zsh: stop backward-kill-word on directory delimiter

In zsh, how can I set up the line editor such that backward-kill-word stops on a directory separator? Currently in my bash setup, if I type
cd ~/devel/sandbox
and then hit C-w point will be right after devel/. In my zsh setup, point would be after cd . I'd like to set up zsh so it behaves similarly to bash.
For recent versions of zsh, you can simply add:
autoload -U select-word-style
select-word-style bash
to your zshrc as described in the zsh manual (also man zshcontrib).
Another option is to set WORDCHARS (non-alphanumeric chars treated as part of a word) to something that doesn't include /.
You can also tweak this if you'd prefer ^w to break on dot, underscore, etc. In ~/.zshrc I have:
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
Here's what worked for me. unspecified word-style was required otherwise zsh didn't seem to respect the WORDCHARS.enter code here
WORDCHARS=' *?_-.[]~=&;!#$%^(){}<>/'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified
Here's more info on why this works.
A quick google reveals:
Backward Kill
Or, perhaps a better fix:
Bash Style Backward Kill

Resources