# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.config/zsh/.zshrc. # Initialization code that may require console input (password prompts, [y/n] # confirmations, etc.) must go above this block; everything else may go below. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" fi # Created by newuser for 5.8 # Enable colors: autoload -U colors && colors # History in cache directory: HISTSIZE=10000 SAVEHIST=10000 HISTFILE=~/.cache/zsh/history HISTCONTROL=ereasedups # Basic auto/tab complete: autoload -U compinit promptinit zstyle ':completion:*' menu select zmodload zsh/complist compinit _comp_options+=(globdots) # Include hidden files. #promptinit; prompt gentoo # vi mode bindkey -v export KEYTIMEOUT=1 # Use vim keys in tab complete menu: bindkey -M menuselect 'h' vi-backward-char bindkey -M menuselect 'k' vi-up-line-or-history bindkey -M menuselect 'l' vi-forward-char bindkey -M menuselect 'j' vi-down-line-or-history bindkey -v '^?' backward-delete-char bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word bindkey "^[[3~" delete-char bindkey "^[3;5~" delete-char # Change cursor shape for different vi modes. function zle-keymap-select { if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then echo -ne '\e[1 q' elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then echo -ne '\e[5 q' fi } zle -N zle-keymap-select zle-line-init() { zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) echo -ne "\e[5 q" } zle -N zle-line-init echo -ne '\e[5 q' # Use beam shape cursor on startup. preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt. # Use ranger to switch directories and bind it to ctrl-o ranger_cd() { temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then cd -- "$chosen_dir" fi rm -f -- "$temp_file" } bindkey -s '^o' 'ranger_cd\n' ranger_pushd() { temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" ranger --choosedir="$temp_file" -- "${@:-$PWD}" if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then pushd -- "$chosen_dir" fi rm -f -- "$temp_file" } bindkey -s '^O' 'ranger_pushd\n' bindkey -s '^r' 'ranger\n' bindkey -s '^n' 'setsid kitty -d $(pwd)\n' bindkey -s '^z' 'bg && disown\n' mkcd() { mkdir $1 cd $1 } retry() { local SLPT=5 [ "$1" = "-t" ] && SLPT="$2" && shift 2 while true; do $@ && break sleep "$SLPT" done } alias test_internet='retry ping google.com -c 1' #alias ls='exa --group-directories-first -l' #alias la='exa --group-directories-first -la' alias ls='ls --group-directories-first --color=auto' alias ll='ls -la --group-directories-first --color=auto' alias la='ls -a --group-directories-first --color=auto' alias less='less -R' alias ci3='$EDITOR $HOME/.config/i3/config' alias cpb='$EDITOR $HOME/.config/polybar/config.ini' alias cpbm='$EDITOR $HOME/.config/polybar/modules.ini' alias czsh='$EDITOR $HOME/.config/zsh/.zshrc' alias cnv='$EDITOR $HOME/.config/nvim/init.vim' alias r='ranger' alias s='swallow' alias dotfiles='/usr/bin/git --git-dir=${XDG_DATA_HOME:-${HOME}/.local/share}/dotfiles --work-tree=$HOME' alias luamake=/home/nerdjp/dev/lua-language-server/3rd/luamake/luamake alias clip='xclip -selection "clipboard"' alias e='edit.sh' alias c='config.sh' pls() { sudo !! } # Edit line in vim with ctrl-e: autoload edit-command-line; zle -N edit-command-line bindkey '^e' edit-command-line setopt auto_cd alias cp='cp -i' alias mv='mv -i' alias dcp='pwd | xclip -selection clipboard' alias ffmpeg='ffmpeg -hide_banner' alias ffprobe='ffprobe -hide_banner' alias iv='nsxiv' alias mp='ncmpcpp' alias vi='nvim' alias grep='grep --color=auto' source /usr/share/fzf/key-bindings.zsh #source /usr/share/fzf/completion.zsh alias gs='git status' alias gb='git branch' alias gc='git checkout' alias gcb='git checkout -b' alias gf='git pull' alias gp='git pull' smv() { [[ -n $1 ]] && mv $(\ls | fzf -m) $1 } gbc() { git branch $@ && git checkout $@ } fzfg() { JOB=$(jobs | fzf | cut -d ' ' -f 1 | sed -e 's/\[/%/' -e 's/\]//') [ -n "$JOB" ] && fg "$JOB" } evi() { if [ -z "${1}" ]; then EBUILD_PATH="/var/db/repos/" else EBUILD_PATH="$(equery w ${1})" fi [ -n "${EBUILD_PATH}" ] && vi ${EBUILD_PATH} } detach() { JOBS=$(jobs) if [ -n "$JOBS" ]; then [ "$(wc -l <<< ${JOBS})" -le 1 ] && { bg && sleep 0.1 && disown && return } JOB=$(fzf <<< ${JOBS} | cut -d ' ' -f 1 | sed -e 's/\[/%/' -e 's/\]//') echo $JOB bg "$JOB" && disown "$JOB" fi } ZSH_AUTOSUGGEST_STRATEGY=(history completion) # make kernel # sync # update # myip # open ports #eval "$(starship init zsh)" autoload -Uz vcs_info zstyle ':vcs_info:*' formats ' %b' preexec_timer() { SECONDS=0 } preexec_functions+=( preexec_timer ) precmd_jobs() { local IFS=" " for job in $(jobs); do if [[ "$job" =~ "running" ]]; then printf "\033[38;5;2m %s" "${job##running}" elif [[ "$job" =~ "suspended" ]]; then printf "\033[38;5;3m %s" "${job##suspended}" else printf "%s" "${job}" fi done } preexec_rename() { printf '\033]2;%s@%s: %s\033\\' ${USER} ${HOST} ${1} } precmd_vcs_info() { vcs_info } precmd_functions+=( precmd_vcs_info precmd_jobs precmd_rename ) preexec_functions+=( preexec_rename ) setopt prompt_subst PROMPT='%F{magenta}%n@%m%f %F{blue}%1~%f %(?,[,%F{red}[%f) ' #PROMPT='%F{magenta}%f %F{blue}%1~%f %(?,[,%F{red}[%f) ' # RPROMPT=' %(?,],%F{red}]%f)' #%F{cyan}${vcs_info_msg_0_}%f' #%1(S,took $(format-time $SECONDS),)' #%F{magenta}%D{%I:%m %p}%f' #paleofetch # Load zsh-syntax-highlighting; should be last. source /usr/share/zsh/site-functions/zsh-syntax-highlighting.zsh source /usr/share/zsh/site-functions/zsh-autosuggestions.zsh printf '\033]2;%s@%s\033\\' $USER $HOST cat "${HOME}/doc/ascii-arts/woman.txt" attach_tmux_group() { if [[ -z ${TMUX} ]]; then local group="${1:-common}" local session=$(tmux list-sessions -F "#S:#{session_group}:#{session_attached}" \ | grep ":${group}:0" | cut -d ':' -f 1) if [[ -n ${session} ]]; then exec tmux attach -t "${session}" else tmux new-window -at "${group}:" tmux new -t "${group}" fi fi } #attach_tmux_group