feat: migrate from Oh-My-Zsh to ZInit
This commit is contained in:
@@ -9,9 +9,9 @@ alias apps='cd ~/.local/share/applications/'
|
||||
alias louis='ssh anton@192.168.178.48'
|
||||
|
||||
# LS
|
||||
alias ls='lsd'
|
||||
alias la='lsd -a'
|
||||
alias ll='lsd -l'
|
||||
alias ls='ls --color=always -F'
|
||||
alias la='ls -a'
|
||||
alias ll='ls -l'
|
||||
|
||||
# WG
|
||||
alias wgon='wg-quick up ~/Downloads/wg0.conf'
|
||||
|
||||
6
zsh/completion.sh
Normal file
6
zsh/completion.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
setopt interactivecomments # VERY IMPORTANT LINE! Completions will be very bad without it
|
||||
|
||||
zinit ice as"completion"
|
||||
zinit light zsh-users/zsh-completions
|
||||
|
||||
zinit light marlonrichert/zsh-autocomplete
|
||||
@@ -31,48 +31,3 @@ split() {
|
||||
(kitty . &)
|
||||
}
|
||||
|
||||
# === FUNCTIONS FOR COMMAND TIMING ===
|
||||
|
||||
# Function to capture the start time of the command
|
||||
preexec() {
|
||||
timer_start=$EPOCHSECONDS
|
||||
}
|
||||
|
||||
# Function to capture the end time of the command and calculate the elapsed time
|
||||
precmd() {
|
||||
local timer_end=$EPOCHSECONDS
|
||||
local elapsed=$((timer_end - timer_start))
|
||||
|
||||
# Reset RPROMPT
|
||||
RPROMPT=""
|
||||
|
||||
if (( elapsed > 36000 )); then
|
||||
return
|
||||
fi
|
||||
|
||||
if (( elapsed > 0 )); then
|
||||
local color time_str
|
||||
if (( elapsed >= 60 )); then
|
||||
local minutes=$((elapsed / 60))
|
||||
local seconds=$((elapsed % 60))
|
||||
time_str="${minutes}m ${seconds}s"
|
||||
color="%{$fg_bold[red]%}"
|
||||
elif (( elapsed >= 10 )); then
|
||||
time_str="${elapsed}s"
|
||||
color="%{$fg_bold[blue]%}"
|
||||
elif (( elapsed >= 5 )); then
|
||||
time_str="${elapsed}s"
|
||||
color="%{$fg_bold[yellow]%}"
|
||||
elif (( elapsed >= 1 )); then
|
||||
time_str="${elapsed}s"
|
||||
color="%{$fg_bold[green]%}"
|
||||
fi
|
||||
|
||||
# Set RPROMPT if elapsed time is greater than or equal to 1 second
|
||||
if [[ -n $time_str ]]; then
|
||||
RPROMPT="${color}${time_str}%{$reset_color%}"
|
||||
fi
|
||||
fi
|
||||
|
||||
timer_start=0
|
||||
}
|
||||
|
||||
27
zsh/git.sh
Normal file
27
zsh/git.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
function git_prompt_info() {
|
||||
# If we are on a folder not tracked by git, get out.
|
||||
# Otherwise, check for hide-info at global and local repository level
|
||||
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
|
||||
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Get either:
|
||||
# - the current branch name
|
||||
# - the tag name if we are on a tag
|
||||
# - the short SHA of the current commit
|
||||
local ref
|
||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
||||
|| return 0
|
||||
|
||||
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
||||
local upstream
|
||||
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )); then
|
||||
upstream=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) \
|
||||
&& upstream=" -> ${upstream}"
|
||||
fi
|
||||
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
}
|
||||
17
zsh/plugins.sh
Normal file
17
zsh/plugins.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
# Plugins
|
||||
zinit ice blockf
|
||||
|
||||
zinit light zsh-users/zsh-syntax-highlighting
|
||||
# zinit light zdharma-continuum/fast-syntax-highlighting
|
||||
|
||||
# completion
|
||||
# [ -f ~/zsh/completion.sh ] && source ~/zsh/completion.sh
|
||||
|
||||
# oh-my-zsh plugins
|
||||
# zinit snippet OMZ::/plugins/colored-man-pages/colored-man-pages.plugin.zsh
|
||||
# zinit snippet OMZ::/plugins/sudo/sudo.plugin.zsh
|
||||
zinit snippet OMZP::colored-man-pages
|
||||
zinit snippet OMZP::sudo
|
||||
zinit snippet OMZP::git
|
||||
zinit snippet OMZ::lib/git.zsh
|
||||
|
||||
131
zsh/prompt.sh
Normal file
131
zsh/prompt.sh
Normal file
@@ -0,0 +1,131 @@
|
||||
# Custom prompt
|
||||
update_prompt() {
|
||||
ret_code=$?
|
||||
PROMPT=""
|
||||
|
||||
# Git
|
||||
if [[ $(git_repo_name) ]]; then
|
||||
# PROMPT+="%{$fg[yellow]%}$(git remote show | head -n 1)"
|
||||
# PROMPT+="%{$fg_bold[magenta] $(git_repo_name)"
|
||||
# PROMPT+="%{$fg_bold[blue]($(git_current_branch))%{$fg[white]%}:"
|
||||
PROMPT+="%{$fg[yellow]%}$(git remote show | head -n 1) %{$fg_bold[magenta]%}$(git_repo_name)%{$fg_bold[blue]%}($(git_current_branch))%{$fg[white]%}:"
|
||||
|
||||
fi
|
||||
|
||||
# Path
|
||||
PROMPT+="%{$fg[cyan]%}%c%{$reset_color%} "
|
||||
|
||||
# Arrow
|
||||
if [[ started -eq 0 ]] || [[ $ret_code -eq 0 ]]; then
|
||||
PROMPT+="%{$fg_bold[green]%}%1{➜%} "
|
||||
else
|
||||
PROMPT+="%{$fg[red]%}%? %{$fg_bold[red]%}%1{➜%} "
|
||||
fi
|
||||
# PROMPT+="%(?:%{$fg_bold[green]%}%1{➜%} :%{$fg[red]%}(%?%) %{$fg_bold[red]%}%1{➜%} )"
|
||||
# PROMPT+="%(?:%{${started:+$fg_bold[green]}${started:=$fg[green]}%}%1{➜%} :%{${started:+$fg_bold[green]%)"
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
update_prompt
|
||||
|
||||
# Define a map of error codes to messages
|
||||
declare -A ERROR_MESSAGES=(
|
||||
[64]="USAGE"
|
||||
[65]="FORMAT"
|
||||
[68]="HOSTNAME"
|
||||
[69]="UNAVAIL"
|
||||
[70]="SOFTWARE"
|
||||
[71]="OSERR"
|
||||
[72]="OSFILE"
|
||||
[73]="CREATEFAIL"
|
||||
[74]="IOERR"
|
||||
[75]="TEMP"
|
||||
[76]="PROTOCOL"
|
||||
[77]="DENIED"
|
||||
[78]="CONFERR" # Configuration error
|
||||
[126]="EXECFAIL"
|
||||
[127]="COMMAND" # Command not found
|
||||
[130]="SIGINT"
|
||||
[137]="SIGKILL"
|
||||
# Add more error codes and messages as needed
|
||||
)
|
||||
|
||||
# === FUNCTIONS FOR COMMAND TIMING ===
|
||||
|
||||
# Function to capture the start time of the command in milliseconds
|
||||
preexec() {
|
||||
started=1
|
||||
timer_start=$(( $(date +%s%3N) )) # Captures current time in milliseconds
|
||||
}
|
||||
|
||||
# Function to capture the end time of the command and calculate the elapsed time
|
||||
precmd() {
|
||||
update_prompt
|
||||
if [[ started -eq 0 ]]; then
|
||||
RPROMPT=""
|
||||
return
|
||||
fi
|
||||
started=0
|
||||
|
||||
local timer_end=$(( $(date +%s%3N) )) # Captures current time in milliseconds
|
||||
local elapsed=$((timer_end - timer_start))
|
||||
|
||||
# Reset RPROMPT
|
||||
RPROMPT=""
|
||||
|
||||
# Handle error codes: Prepend the error message if the command failed
|
||||
if [[ ret_code -ne 0 ]]; then
|
||||
local error_msg=${ERROR_MESSAGES[$ret_code]}
|
||||
if [[ -n $error_msg ]]; then
|
||||
RPROMPT="%{$fg_bold[red]%}(${error_msg})%{$reset_color%}$RPROMPT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Do not display the time if it is above 100 hours (360000000 ms)
|
||||
if (( elapsed > 360000000 )); then
|
||||
return
|
||||
fi
|
||||
|
||||
if (( elapsed > 0 )); then
|
||||
local color time_str
|
||||
local seconds=$((elapsed / 1000))
|
||||
local milliseconds=$((elapsed % 1000))
|
||||
|
||||
if (( seconds >= 60 )); then
|
||||
local minutes=$((seconds / 60))
|
||||
seconds=$((seconds % 60))
|
||||
if (( minutes >= 60 )); then
|
||||
local hours=$((minutes / 60))
|
||||
minutes=$((minutes % 60))
|
||||
time_str="${hours}h ${minutes}m"
|
||||
if (( seconds > 0 )); then
|
||||
time_str="${time_str} ${seconds}s"
|
||||
fi
|
||||
else
|
||||
time_str="${minutes}m"
|
||||
if (( seconds > 0 )); then
|
||||
time_str="${time_str} ${seconds}s"
|
||||
fi
|
||||
fi
|
||||
color="%{$fg[red]%}"
|
||||
elif (( seconds >= 10 )); then
|
||||
time_str="${seconds}s"
|
||||
color="%{$fg[orange]%}"
|
||||
elif (( seconds >= 5 )); then
|
||||
time_str="${seconds}s"
|
||||
color="%{$fg[yellow]%}"
|
||||
elif (( seconds >= 1 )); then
|
||||
time_str="${seconds}s ${milliseconds}ms"
|
||||
color="%{$fg_bold[green]%}"
|
||||
else
|
||||
time_str="${milliseconds}ms"
|
||||
color="%{$fg_bold[green]%}"
|
||||
fi
|
||||
|
||||
# Append the time string to RPROMPT
|
||||
if [[ -n $time_str ]]; then
|
||||
RPROMPT="${RPROMPT} ${color}${time_str}%{$reset_color%}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user