zsh
Ctrl-u
compinit
The first 3 lines of of simple .zshrc
is:
What it does is simply bring the functions compinit
and promptinit
into
scope and execute them. These functions will be in scope if they're under $fpath
, this will be the
case if zsh if installed properly in your system.
compinit will initialize completion for the current session when called directly, in .zshrc
.
zshrc complete
This is what I roll with for now. Might need to improve it someday after reading the docs and figuring out what's what.
# Enable colors and change prompt:
autoload -U colors && colors
PS1="%B%{$fg[blue]%}%n%{$fg[white]%}@%{$fg[white]%}%M %{$fg[magenta]%}%~%{$fg[white]%}%{$reset_color%} $%b "
# For some reason, this block should be preceding the block that follows it.
HISTSIZE=10000000
SAVEHIST=10000000
HISTFILE=~/.zsh_history
# 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 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
export HISTORY_IGNORE=""
# Enable interactive comments
setopt INTERACTIVECOMMENTS
# The location in this file where compinit is important
# See 20.2.1 https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-System-Configuration
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots) # Include hidden files.
# emacs mode on shell. vi on editor.
bindkey -e
# hjkl is still the better way to navigate menu
bindkey -M menuselect 'h' backward-char
bindkey -M menuselect 'k' up-line-or-history
bindkey -M menuselect 'l' forward-char
bindkey -M menuselect 'j' down-line-or-history
# https://unix.stackexchange.com/questions/522663/ctrl-u-deletes-whole-line-regardless-of-cursor-position
bindkey \^U backward-kill-line
# Source file generated by fzf --zsh
source "$HOME/.fzf.zsh"
export FZF_DEFAULT_OPTS="--height 50% --layout=reverse --multi --bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle"
# source /usr/share/zsh/plugins/zsh-z/zsh-z.plugin.zsh
# Useful aliases
alias gn="cd $HOME/vectorspacexyz.github.io/docs"
alias ls='ls --color'
export PATH="$PATH:$HOME/bin:$HOME/flutter/bin:$HOME/.pub-cache/bin:$HOME/.local/bin"
function bwupdate() {
bw list items > /tmp/result.json
[[ -s /tmp/result.json ]] && return
jq -r '.[] | .login.username as $username | .login.password as $password | .id as $id | .login.uris[] | "\($id) \($username) \($password) \(.uri)"' /tmp/result.json > /home/vector/.bw-entries
rm /tmp/result.json
[[ -z /tmp/.bw-entries ]] && return
gpg --symmetric --cipher-algo AES256 /home/vector/.bw-entries
rm /home/vector/.bw-entries
}
function getpasswd() {
read -s "password?password: " || return
gpg --batch --passphrase "$password" --decrypt ~/.bw-entries.gpg > /tmp/decrypted-bw-entries.txt
if ! [ $? -eq 0 ];
then
echo "GPG decryption failed."
unset password
return 1
else
fi
unset password
CHOICE=$(cat /tmp/decrypted-bw-entries.txt | cut -d' ' -f2- | fzf)
[[ -z $CHOICE ]] && return
LOGINID=$(cut -d' ' -f1 <<<$CHOICE)
BWPASSWORD=$(cut -d' ' -f2 <<<$CHOICE)
LINK=$(cut -d' ' -f3- <<<$CHOICE)
echo $BWPASSWORD | xclip -i -selection clipboard
echo $LOGINID | xclip -i -selection primary
echo $LINK
notify-send "$LINK: $LOGINID"
[[ -e /tmp/decrypted-bw-entries.txt ]] && rm /tmp/decrypted-bw-entries.txt
}
# Load zsh-syntax-highlighting; should be last.
# pacman -S zsh-syntax-highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
export ZSH_HIGHLIGHT_STYLES[comment]="fg=#808080"