mirror of
https://github.com/danielepintore/dotfiles.git
synced 2026-06-15 20:25:13 +02:00
zsh: made config modular
This commit is contained in:
@@ -2,12 +2,7 @@
|
||||
# Exaples:
|
||||
# export NAME="VALUE"
|
||||
# export PATH="$PATH:/newPath"
|
||||
export PATH="$PATH:/opt/flutter/bin/"
|
||||
export PATH="$PATH:/home/daniele/go/bin/"
|
||||
|
||||
export PATH="$PATH:$HOME/.local/scripts/"
|
||||
|
||||
export CAPACITOR_ANDROID_STUDIO_PATH="/home/daniele/.local/share/JetBrains/Toolbox/apps/android-studio/bin/studio.sh"
|
||||
source "${ZDOTDIR}/conf.d/_env.zsh"
|
||||
|
||||
# Launch Hyprland via uwsm
|
||||
# Check if we are inside a tmux session
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
. "$HOME/.cargo/env"
|
||||
@@ -1,94 +1,16 @@
|
||||
# Load aliases
|
||||
source $HOME/.config/zsh/aliases.zsh
|
||||
# Load seperated config files
|
||||
for conf in $(ls "${ZDOTDIR}/conf.d/"[^_]*.zsh | sort); do
|
||||
source "${conf}"
|
||||
done
|
||||
unset conf
|
||||
|
||||
# Enable colors and change prompt
|
||||
autoload -U colors && colors
|
||||
# Load custom functions
|
||||
for func in $(ls "${ZDOTDIR}/functions/"[^_]*.zsh | sort); do
|
||||
source "${func}"
|
||||
done
|
||||
unset func
|
||||
|
||||
# Get git branch for the prompt
|
||||
autoload -Uz vcs_info # load function
|
||||
zstyle ':vcs_info:*' enable git # disable all vcs except git
|
||||
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})hole%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f'
|
||||
zstyle ':vcs_info:*' formats '%F{9}( %b)%f '
|
||||
precmd () { vcs_info }
|
||||
setopt prompt_subst
|
||||
|
||||
#PS1="\$vcs_info_msg_0_ $PS1"
|
||||
PS1=' %F{#91C79C}%~ %f${vcs_info_msg_0_}'
|
||||
|
||||
# History in zsh dir
|
||||
HISTFILE=~/.config/zsh/histfile
|
||||
HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
|
||||
# set vim as prefered editor
|
||||
bindkey -v
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
# Auto completition
|
||||
if [[ -o interactive ]]; then
|
||||
function setup_completion {
|
||||
autoload -U compinit
|
||||
zstyle ':completion:*' menu select
|
||||
zmodload zsh/complist
|
||||
compinit
|
||||
_comp_options+=(globdots) # Include hidden files.
|
||||
unset -f setup_completion # cleanup the function
|
||||
# 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
|
||||
}
|
||||
precmd_functions+=(setup_completion)
|
||||
fi
|
||||
|
||||
bindkey -v '^?' backward-delete-char
|
||||
|
||||
# ctrl+arrows to move between words
|
||||
bindkey -M viins '\e[1;5D' backward-word # Ctrl+Left in insert mode
|
||||
bindkey -M viins '\e[1;5C' forward-word # Ctrl+Right in insert mode
|
||||
|
||||
# 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.
|
||||
|
||||
# Edit line in vim with ctrl-e:
|
||||
autoload edit-command-line; zle -N edit-command-line; zstyle :zle:edit-command-line editor nvim;
|
||||
bindkey '^e' edit-command-line
|
||||
|
||||
# Add reverse seach with ctrl-r
|
||||
bindkey -v '^R' history-incremental-search-backward
|
||||
|
||||
# Load zsh-syntax-highlighting; should be last. (You have to install it:
|
||||
# Load zsh-syntax-highlighting; should be the last thing to do. (You have to install it:
|
||||
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md)
|
||||
# Theme section
|
||||
source $HOME/.config/zsh/themes/dracula.zsh
|
||||
# End theme section
|
||||
|
||||
# Set up fzf key bindings and fuzzy completion
|
||||
eval "$(fzf --zsh)"
|
||||
|
||||
# tmux-sessionizer
|
||||
bindkey -s ^n "tmux-sessionizer\n"
|
||||
|
||||
# Zsh syntax highlighting
|
||||
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||
|
||||
source ~/.config/zsh/functions
|
||||
|
||||
8
.config/zsh/conf.d/01_theme.zsh
Normal file
8
.config/zsh/conf.d/01_theme.zsh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Enable colors and change prompt
|
||||
autoload -U colors && colors
|
||||
|
||||
# Theme section
|
||||
source "${ZDOTDIR}/themes/coolbeans.zsh"
|
||||
|
||||
33
.config/zsh/conf.d/02_prompt.zsh
Normal file
33
.config/zsh/conf.d/02_prompt.zsh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Get git branch for the prompt
|
||||
autoload -Uz vcs_info # load function
|
||||
zstyle ':vcs_info:*' enable git # disable all vcs except git
|
||||
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})hole%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f'
|
||||
zstyle ':vcs_info:*' formats '%F{9}( %b)%f '
|
||||
precmd () { vcs_info }
|
||||
setopt prompt_subst
|
||||
|
||||
PS1=' %F{#CEFFAC}%~ %f${vcs_info_msg_0_}'
|
||||
|
||||
# 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.
|
||||
|
||||
20
.config/zsh/conf.d/03_auto_completition.zsh
Normal file
20
.config/zsh/conf.d/03_auto_completition.zsh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Auto completition
|
||||
if [[ -o interactive ]]; then
|
||||
function setup_completion {
|
||||
autoload -U compinit
|
||||
zstyle ':completion:*' menu select
|
||||
zmodload zsh/complist
|
||||
compinit
|
||||
_comp_options+=(globdots) # Include hidden files.
|
||||
unset -f setup_completion # cleanup the function
|
||||
# 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
|
||||
}
|
||||
precmd_functions+=(setup_completion)
|
||||
fi
|
||||
|
||||
22
.config/zsh/conf.d/04_binds.zsh
Normal file
22
.config/zsh/conf.d/04_binds.zsh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env zsh
|
||||
# set vim as prefered editor
|
||||
bindkey -v
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
# ctrl+arrows to move between words
|
||||
bindkey -M viins '\e[1;5D' backward-word # Ctrl+Left in insert mode
|
||||
bindkey -M viins '\e[1;5C' forward-word # Ctrl+Right in insert mode
|
||||
|
||||
# Edit line in vim with ctrl-e:
|
||||
autoload edit-command-line; zle -N edit-command-line; zstyle :zle:edit-command-line editor nvim;
|
||||
bindkey '^e' edit-command-line
|
||||
|
||||
# Add reverse seach with ctrl-r
|
||||
bindkey -v '^R' history-incremental-search-backward
|
||||
|
||||
# Set up fzf key bindings and fuzzy completion
|
||||
eval "$(fzf --zsh)"
|
||||
|
||||
# tmux-sessionizer
|
||||
bindkey -s ^n "tmux-sessionizer\n"
|
||||
|
||||
6
.config/zsh/conf.d/05_command_history.zsh
Normal file
6
.config/zsh/conf.d/05_command_history.zsh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env zsh
|
||||
# History in zsh dir
|
||||
HISTFILE=~/.config/zsh/histfile
|
||||
HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env zsh
|
||||
# nvim alias
|
||||
alias vim=nvim
|
||||
|
||||
13
.config/zsh/conf.d/_env.zsh
Normal file
13
.config/zsh/conf.d/_env.zsh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env zsh
|
||||
# This file has a _ prefix, this means that it is ignored and not automatically
|
||||
# loaded in .zshrc, in fact is manually loaded in .zprofile
|
||||
# Environment variable should be setted up here
|
||||
# export NAME=VALUE
|
||||
path+=~/go/bin/
|
||||
|
||||
export ANDROID_HOME=~/Android/Sdk
|
||||
path+=$ANDROID_HOME/tools
|
||||
path+=$ANDROID_HOME/tools/bin
|
||||
path+=$ANDROID_HOME/platform-tools
|
||||
|
||||
export EDITOR=nvim
|
||||
27
.config/zsh/functions/tmux-sessionizer.zsh
Normal file
27
.config/zsh/functions/tmux-sessionizer.zsh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
tmux-sessionizer() {
|
||||
if [[ $# -eq 1 ]]; then
|
||||
selected=$1
|
||||
else
|
||||
selected=$(find ~/Documents ~/Documents/projects ~/ -mindepth 1 -maxdepth 1 -type d | fzf)
|
||||
fi
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
selected_name=$(basename "$selected" | tr . _)
|
||||
|
||||
if [[ -z $TMUX ]]; then
|
||||
if ! tmux has-session -t=$selected_name 2>/dev/null; then
|
||||
tmux new-session -ds $selected_name -c $selected
|
||||
fi
|
||||
tmux attach-session -t$selected_name
|
||||
else
|
||||
if ! tmux has-session -t=$selected_name 2>/dev/null; then
|
||||
tmux new-session -ds $selected_name -c $selected
|
||||
fi
|
||||
tmux switch-client -t$selected_name
|
||||
fi
|
||||
}
|
||||
17
.config/zsh/functions/web2app-remove.zsh
Normal file
17
.config/zsh/functions/web2app-remove.zsh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
web2app-remove() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: web2app-remove <AppName>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local APP_NAME="$1"
|
||||
local ICON_DIR="$HOME/.local/share/applications/icons"
|
||||
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
|
||||
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
|
||||
|
||||
rm "$DESKTOP_FILE"
|
||||
rm "$ICON_PATH"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Create a desktop launcher for a web app
|
||||
web2app() {
|
||||
if [ "$#" -ne 3 ]; then
|
||||
@@ -33,18 +35,3 @@ EOF
|
||||
|
||||
chmod +x "$DESKTOP_FILE"
|
||||
}
|
||||
|
||||
web2app-remove() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: web2app-remove <AppName>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local APP_NAME="$1"
|
||||
local ICON_DIR="$HOME/.local/share/applications/icons"
|
||||
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
|
||||
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
|
||||
|
||||
rm "$DESKTOP_FILE"
|
||||
rm "$ICON_PATH"
|
||||
}
|
||||
91
.config/zsh/themes/coolbeans.zsh
Normal file
91
.config/zsh/themes/coolbeans.zsh
Normal file
@@ -0,0 +1,91 @@
|
||||
# Dracula Theme (for zsh-syntax-highlighting)
|
||||
#
|
||||
# https://github.com/zenorocha/dracula-theme
|
||||
#
|
||||
# Copyright 2021, All rights reserved
|
||||
#
|
||||
# Code licensed under the MIT license
|
||||
# http://zenorocha.mit-license.org
|
||||
#
|
||||
# @author George Pickering <@bigpick>
|
||||
# @author Zeno Rocha <hi@zenorocha.com>
|
||||
# Paste this files contents inside your ~/.zshrc before you activate zsh-syntax-highlighting
|
||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main cursor)
|
||||
typeset -gA ZSH_HIGHLIGHT_STYLES
|
||||
# Default groupings per, https://spec.draculatheme.com, try to logically separate
|
||||
# possible ZSH_HIGHLIGHT_STYLES settings accordingly...?
|
||||
#
|
||||
# Italics not yet supported by zsh; potentially soon:
|
||||
# https://github.com/zsh-users/zsh-syntax-highlighting/issues/432
|
||||
# https://www.zsh.org/mla/workers/2021/msg00678.html
|
||||
# ... in hopes that they will, labelling accordingly with ,italic where appropriate
|
||||
#
|
||||
# Main highlighter styling: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
|
||||
#
|
||||
## General
|
||||
### Diffs
|
||||
### Markup
|
||||
## Classes
|
||||
## Comments
|
||||
ZSH_HIGHLIGHT_STYLES[comment]='fg=#6272A4'
|
||||
## Constants
|
||||
## Entitites
|
||||
## Functions/methods
|
||||
ZSH_HIGHLIGHT_STYLES[alias]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[global-alias]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[function]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[command]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[precommand]='fg=#BBBBBB,italic'
|
||||
ZSH_HIGHLIGHT_STYLES[autodirectory]='fg=#C6C5FE,italic'
|
||||
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=#C6C5FE'
|
||||
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=#C6C5FE'
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=#BD93F9'
|
||||
## Keywords
|
||||
## Built ins
|
||||
ZSH_HIGHLIGHT_STYLES[builtin]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=#BBBBBB'
|
||||
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=#BBBBBB'
|
||||
## Punctuation
|
||||
ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=#A8FF60'
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-unquoted]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]='fg=#A8FF60'
|
||||
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=#A8FF60'
|
||||
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]='fg=#A8FF60'
|
||||
## Serializable / Configuration Languages
|
||||
## Storage
|
||||
## Strings
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution-quoted]='fg=#FFFFB6'
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-quoted]='fg=#FFFFB6'
|
||||
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=#FFFFB6'
|
||||
ZSH_HIGHLIGHT_STYLES[single-quoted-argument-unclosed]='fg=#FFB6B0'
|
||||
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=#FFFFB6'
|
||||
ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]='fg=#FFB6B0'
|
||||
ZSH_HIGHLIGHT_STYLES[rc-quote]='fg=#FFFFB6'
|
||||
## Variables
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument-unclosed]='fg=#FFB6B0'
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[assign]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[named-fd]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[numeric-fd]='fg=#F8F8F2'
|
||||
## No category relevant in spec
|
||||
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=#FFB6B0'
|
||||
ZSH_HIGHLIGHT_STYLES[path]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[path_pathseparator]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[globbing]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=#BD93F9'
|
||||
#ZSH_HIGHLIGHT_STYLES[command-substitution]='fg=?'
|
||||
#ZSH_HIGHLIGHT_STYLES[command-substitution-unquoted]='fg=?'
|
||||
#ZSH_HIGHLIGHT_STYLES[process-substitution]='fg=?'
|
||||
#ZSH_HIGHLIGHT_STYLES[arithmetic-expansion]='fg=?'
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-unclosed]='fg=#FFB6B0'
|
||||
ZSH_HIGHLIGHT_STYLES[redirection]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[arg0]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[default]='fg=#F8F8F2'
|
||||
ZSH_HIGHLIGHT_STYLES[cursor]='standout'
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [[ $# -eq 1 ]]; then
|
||||
selected=$1
|
||||
else
|
||||
selected=$(find ~/Documents ~/Documents/projects ~/ -mindepth 1 -maxdepth 1 -type d | fzf)
|
||||
fi
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
exit -1
|
||||
fi
|
||||
|
||||
selected_name=$(basename "$selected" | tr . _)
|
||||
|
||||
if [[ -z $TMUX ]]; then
|
||||
if ! tmux has-session -t=$selected_name 2>/dev/null; then
|
||||
tmux new-session -ds $selected_name -c $selected
|
||||
fi
|
||||
tmux attach-session -t$selected_name
|
||||
else
|
||||
if ! tmux has-session -t=$selected_name 2>/dev/null; then
|
||||
tmux new-session -ds $selected_name -c $selected
|
||||
fi
|
||||
tmux switch-client -t$selected_name
|
||||
fi
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
branch_name=$(basename $1)
|
||||
session_name=$(tmux display-message -p "#S")
|
||||
clean_name=$(echo $branch_name | tr "./" "__")
|
||||
target="$session_name:$clean_name"
|
||||
|
||||
if ! tmux has-session -t $target 2> /dev/null; then
|
||||
tmux neww -dn $clean_name
|
||||
fi
|
||||
|
||||
shift
|
||||
tmux send-keys -t $target "$*"
|
||||
Reference in New Issue
Block a user