Switch to fish shell
This commit is contained in:
16
.config/fish/alias.fish
Normal file
16
.config/fish/alias.fish
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Utilities
|
||||||
|
alias cls clear
|
||||||
|
|
||||||
|
alias vencord 'sh -c "$(curl -sS https://raw.githubusercontent.com/Vendicated/VencordInstaller/main/install.sh)"'
|
||||||
|
|
||||||
|
# Places
|
||||||
|
alias applications 'cd ~/.local/share/applications/'
|
||||||
|
alias dot 'cd ~/dotfiles'
|
||||||
|
|
||||||
|
# Layout
|
||||||
|
alias smap layout # Switch map
|
||||||
|
alias us 'layout -t us'
|
||||||
|
alias sv 'layout -t se'
|
||||||
|
|
||||||
|
# SSH
|
||||||
|
alias louis 'echo "$(set_color red)You changed this dimwit, use \'vpn\' instead"'
|
||||||
66
.config/fish/config.fish
Normal file
66
.config/fish/config.fish
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
set fish_greeting '( .-.)'
|
||||||
|
|
||||||
|
set PI 3.141592653589
|
||||||
|
|
||||||
|
set _TEMP '/tmp/anton/'
|
||||||
|
|
||||||
|
if not test -d $_TEMP
|
||||||
|
mkdir -p $_TEMP
|
||||||
|
end
|
||||||
|
|
||||||
|
source ~/.config/fish/alias.fish
|
||||||
|
|
||||||
|
set -l last_status $status
|
||||||
|
|
||||||
|
function fish_mode_prompt; end
|
||||||
|
|
||||||
|
function fish_prompt
|
||||||
|
set -l duration $CMD_DURATION
|
||||||
|
|
||||||
|
if test $CMD_DURATION -gt 700
|
||||||
|
set -l seconds $(round -p 2 $(math $duration / 1000 % 60))
|
||||||
|
set seconds $seconds "s"
|
||||||
|
set -l minutes
|
||||||
|
if test $duration -gt 60000
|
||||||
|
set minutes $(round (math $duration / 60000))
|
||||||
|
set minutes $minutes "m "
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
string join '' -- (set_color white) "took " (set_color yellow) $minutes $seconds
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l mode
|
||||||
|
switch (echo $fish_bind_mode)
|
||||||
|
case default
|
||||||
|
set mode $(string join '' -- (set_color --bold red) '[N] ' (set_color normal))
|
||||||
|
case insert
|
||||||
|
set mode $(string join '' -- (set_color --bold cyan) '[I] ' (set_color normal))
|
||||||
|
case replace_one
|
||||||
|
set mode $(string join '' -- (set_color --bold green) '[R] ' (set_color normal))
|
||||||
|
case visual
|
||||||
|
set mode $(string join '' -- (set_color --bold brmagenta) '[V] ' (set_color normal))
|
||||||
|
case '*'
|
||||||
|
set mode $(string join '' -- (set_color --bold red) '[?] ' (set_color normal))
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l last_status $status
|
||||||
|
|
||||||
|
set -l cursor_color $(set_color green)
|
||||||
|
|
||||||
|
if test $last_status -ne 0
|
||||||
|
set last_status $(string join '' -- (set_color red) " [$last_status]")
|
||||||
|
set cursor_color $(set_color red)
|
||||||
|
else
|
||||||
|
set last_status ""
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l git $(string trim -- (fish_vcs_prompt))
|
||||||
|
if test -n "$git"
|
||||||
|
set git $(string join '' -- (set_color yellow) " " (string sub -s 2 $git -e -1) " ")
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l pwd $(string join '' -- (set_color green) (prompt_pwd -D 2 -d 1) (set_color normal))
|
||||||
|
|
||||||
|
string join '' -- $mode $pwd $last_status $git $cursor_color '|> '
|
||||||
|
end
|
||||||
20
.config/fish/functions/clip.fish
Normal file
20
.config/fish/functions/clip.fish
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
function clip
|
||||||
|
set -g stdin
|
||||||
|
if not tty -s >/dev/null
|
||||||
|
read stdin
|
||||||
|
end
|
||||||
|
set stdin $(string trim -- $stdin)
|
||||||
|
|
||||||
|
set -l argv $(string trim -- $argv)
|
||||||
|
if test -n "$argv"
|
||||||
|
echo "$argv" | xclip -selection clipboard
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -n "$stdin"
|
||||||
|
echo "$stdin" | xclip -selection clipboard
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
xclip -selection clipboard -o
|
||||||
|
end
|
||||||
3
.config/fish/functions/into.fish
Normal file
3
.config/fish/functions/into.fish
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
function into
|
||||||
|
mkdir -p "$argv" && cd "$argv"
|
||||||
|
end
|
||||||
61
.config/fish/functions/layout.fish
Normal file
61
.config/fish/functions/layout.fish
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
function layout
|
||||||
|
argparse -n "layout" "v/verbose" "t/target=" -- $argv
|
||||||
|
or return 1
|
||||||
|
|
||||||
|
set _target
|
||||||
|
|
||||||
|
if set -q _flag_target
|
||||||
|
set _target "$_flag_target"
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -f "$_TEMP/curr-layout"
|
||||||
|
if not set -q _flag_target
|
||||||
|
switch (cat "$_TEMP/curr-layout")
|
||||||
|
case us
|
||||||
|
set _target "sv"
|
||||||
|
case se
|
||||||
|
set _target "us"
|
||||||
|
case sv
|
||||||
|
set _target "us"
|
||||||
|
case '*'
|
||||||
|
if set -q _flag_verbose
|
||||||
|
echo "Unregognized layout set in /curr-layout file; stopping..."
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if set -q _flag_verbose; and not set -q _flag_target
|
||||||
|
echo "Could not determine current layout; defaulting to US"
|
||||||
|
end
|
||||||
|
echo "us" > "$_TEMP/curr-layout"
|
||||||
|
if not set -q _flag_target
|
||||||
|
set _target "sv"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not set -q _target
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q _flag_verbose
|
||||||
|
switch (echo $_target)
|
||||||
|
case sv
|
||||||
|
echo "Switching to Swedish layout..."
|
||||||
|
case us
|
||||||
|
echo "Switching to U.S. layout..."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
switch (echo $_target)
|
||||||
|
case sv
|
||||||
|
set _target se
|
||||||
|
case '*'
|
||||||
|
end
|
||||||
|
|
||||||
|
if setxkbmap -layout $_target
|
||||||
|
echo $_target > "$_TEMP/curr-layout"
|
||||||
|
end
|
||||||
|
|
||||||
|
return $status
|
||||||
|
end
|
||||||
22
.config/fish/functions/round.fish
Normal file
22
.config/fish/functions/round.fish
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
function round
|
||||||
|
argparse -n "round" -i "p/precision=!_validate_int" -- $argv
|
||||||
|
or return 1
|
||||||
|
|
||||||
|
set -l value $argv
|
||||||
|
|
||||||
|
set -l precision 0
|
||||||
|
if set -q _flag_precision
|
||||||
|
set precision $_flag_precision
|
||||||
|
end
|
||||||
|
|
||||||
|
set precision $(math 10 ^ $precision)
|
||||||
|
|
||||||
|
set value $(math $value x $precision)
|
||||||
|
|
||||||
|
set -l right $(math $value % 1)
|
||||||
|
|
||||||
|
set value $(math $value - $right)
|
||||||
|
set value $(math $value / $precision)
|
||||||
|
|
||||||
|
echo $value
|
||||||
|
end
|
||||||
84
.config/fish/functions/vpn.fish
Normal file
84
.config/fish/functions/vpn.fish
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
function vpn
|
||||||
|
argparse -n "vpn" -x e,d -x q,s 'e/enable' 'd/disable' 's/status' 'q/quiet' 'f/force' -- $argv
|
||||||
|
or return 1
|
||||||
|
|
||||||
|
set _silent false
|
||||||
|
if set -q _flag_quiet
|
||||||
|
set _silent true
|
||||||
|
end
|
||||||
|
|
||||||
|
set _path ~/wg0.conf
|
||||||
|
set _status false
|
||||||
|
|
||||||
|
if test -f "$_TEMP/vpn-status"
|
||||||
|
switch (cat "$_TEMP/vpn-status")
|
||||||
|
case true
|
||||||
|
set _status true
|
||||||
|
case false
|
||||||
|
set _status false
|
||||||
|
case '*'
|
||||||
|
if not $_quiet
|
||||||
|
echo "Unregognized /vpn-status contents, exiting!"
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not $_silent
|
||||||
|
echo "Did not find status file; creating..."
|
||||||
|
echo "false" >> "$_TEMP/vpn-status"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q _flag_status
|
||||||
|
if $_status
|
||||||
|
echo "VPN is active."
|
||||||
|
else
|
||||||
|
echo "VPN is inactive."
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if not set -q _flag_enable; and not set -q _flag_disable
|
||||||
|
if $_status
|
||||||
|
set _flag_disable
|
||||||
|
else
|
||||||
|
set _flag_enable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q _flag_enable
|
||||||
|
if $_status; and not set -q _flag_force
|
||||||
|
if not $_silent
|
||||||
|
echo "Already enabled."
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if wg-quick up $_path
|
||||||
|
echo "true" > "$_TEMP/vpn-status"
|
||||||
|
if not $_silent
|
||||||
|
echo "Successfully enabled."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return $status
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q _flag_disable
|
||||||
|
if not $_status; and not set -q _flag_force
|
||||||
|
if not $_silent
|
||||||
|
echo "Already disabled."
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if wg-quick down $_path
|
||||||
|
echo "false" > "$_TEMP/vpn-status"
|
||||||
|
if not $_silent
|
||||||
|
echo "Successfully disabled."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return $status
|
||||||
|
end
|
||||||
|
|
||||||
|
return 2
|
||||||
|
end
|
||||||
@@ -21,4 +21,5 @@ color14 #4d7b73
|
|||||||
color7 #b5b8b6
|
color7 #b5b8b6
|
||||||
color15 #5a6169
|
color15 #5a6169
|
||||||
|
|
||||||
selection_foreground #161718
|
selection_foreground #b7bcb9
|
||||||
|
selection_background #2a2e33
|
||||||
@@ -1325,6 +1325,7 @@ enable_audio_bell no
|
|||||||
#: Advanced {{{
|
#: Advanced {{{
|
||||||
|
|
||||||
# shell .
|
# shell .
|
||||||
|
shell /usr/bin/fish
|
||||||
|
|
||||||
#: The shell program to execute. The default value of . means to use
|
#: The shell program to execute. The default value of . means to use
|
||||||
#: whatever shell is set as the default shell for the current user.
|
#: whatever shell is set as the default shell for the current user.
|
||||||
|
|||||||
6
.zshenv
6
.zshenv
@@ -1,6 +0,0 @@
|
|||||||
[ -f ~/zsh/aliases.sh ] && source ~/zsh/aliases.sh
|
|
||||||
[ -f ~/zsh/functions.sh ] && source ~/zsh/functions.sh
|
|
||||||
|
|
||||||
# Path
|
|
||||||
PATH+=":/home/anton/Rider/bin"
|
|
||||||
PATH+=":/home/anton/.cargo/bin"
|
|
||||||
53
.zshrc
53
.zshrc
@@ -1,53 +0,0 @@
|
|||||||
# If you come from bash you might have to change your $PATH.
|
|
||||||
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
# Path to your Oh My Zsh installation.
|
|
||||||
# export ZSH="$HOME/.oh-my-zsh"
|
|
||||||
|
|
||||||
# ZSH_THEME="robbyrussell"
|
|
||||||
|
|
||||||
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
|
||||||
|
|
||||||
# plugins=(
|
|
||||||
# git
|
|
||||||
# zsh-syntax-highlighting
|
|
||||||
# # zsh-autosuggestions
|
|
||||||
# zsh-autocomplete
|
|
||||||
# colored-man-pages
|
|
||||||
# sudo
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
# source $ZSH/oh-my-zsh.sh
|
|
||||||
|
|
||||||
# ZInit
|
|
||||||
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
|
|
||||||
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
|
|
||||||
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
|
|
||||||
source "${ZINIT_HOME}/zinit.zsh"
|
|
||||||
|
|
||||||
# fzf
|
|
||||||
source <(fzf --zsh)
|
|
||||||
|
|
||||||
zinit snippet OMZ::lib/git.zsh
|
|
||||||
|
|
||||||
[ -f ~/zsh/prompt.sh ] && source ~/zsh/prompt.sh
|
|
||||||
[ -f ~/zsh/completion.sh ] && source ~/zsh/completion.sh
|
|
||||||
|
|
||||||
|
|
||||||
# [ -f ~/zsh/aliases.sh ] && source ~/zsh/aliases.sh
|
|
||||||
# [ -f ~/zsh/functions.sh ] && source ~/zsh/functions.sh
|
|
||||||
# Path
|
|
||||||
# PATH+=":/home/anton/Rider/bin"
|
|
||||||
# PATH+=":/home/anton/.cargo/bin"
|
|
||||||
|
|
||||||
zinit ice wait'!0'
|
|
||||||
|
|
||||||
[ -f ~/zsh/plugins.sh ] && source ~/zsh/plugins.sh
|
|
||||||
|
|
||||||
# source ${ZINIT_HOME}/../plugins/marlonrichert---zsh-autocomplete/zsh-autocomplete.plugin.zsh
|
|
||||||
# zstyle ':autocomplete:*' delay 0.1 # seconds (float)
|
|
||||||
|
|
||||||
# Created by `pipx` on 2024-08-28 16:28:46
|
|
||||||
export PATH="$PATH:/home/anton/.local/bin"
|
|
||||||
. "/home/anton/.deno/env"
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# Utility
|
|
||||||
alias ..='cd ..'
|
|
||||||
alias cls='clear'
|
|
||||||
|
|
||||||
alias vencord='sh -c "$(curl -sS https://raw.githubusercontent.com/Vendicated/VencordInstaller/main/install.sh)"'
|
|
||||||
alias apps='cd ~/.local/share/applications/'
|
|
||||||
|
|
||||||
# SSH
|
|
||||||
alias louis='ssh anton@192.168.178.48'
|
|
||||||
|
|
||||||
# LS
|
|
||||||
alias ls='ls --color=always -F'
|
|
||||||
alias la='ls -a'
|
|
||||||
alias ll='ls -l'
|
|
||||||
|
|
||||||
# WG
|
|
||||||
alias wgon='wg-quick up ~/Downloads/wg0.conf'
|
|
||||||
alias wgoff='wg-quick down ~/Downloads/wg0.conf'
|
|
||||||
|
|
||||||
# nvim
|
|
||||||
nv() { neovide $1 & }
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
setopt interactivecomments # VERY IMPORTANT LINE! Completions will be very bad without it
|
|
||||||
|
|
||||||
zstyle ':autocomplete:*' min-delay 0.5 # float
|
|
||||||
zstyle ':autocomplete:*' min-input 2 # int
|
|
||||||
zstyle ':autocomplete:*' insert-unambiguous no
|
|
||||||
|
|
||||||
zinit ice as "autocomplete"
|
|
||||||
zinit light zsh-users/zsh-completions
|
|
||||||
|
|
||||||
zinit light marlonrichert/zsh-autocomplete
|
|
||||||
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
# Very helpful multi-functional clip command.
|
|
||||||
clip() {
|
|
||||||
if [ -t 0 ]; then
|
|
||||||
# Standard input is not a terminal (no pipe input)
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
# No arguments, print clipboard content
|
|
||||||
xclip -selection clipboard -o
|
|
||||||
else
|
|
||||||
# Arguments provided, pass them to xclip
|
|
||||||
echo "$*" | xclip -selection clipboard
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Standard input is a terminal (pipe input)
|
|
||||||
xclip -selection clipboard
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
# copy text
|
|
||||||
# $ clip "hello world"
|
|
||||||
# copy cmd output
|
|
||||||
# $ cat file.js | clip
|
|
||||||
# use copied data as values, for example run a script off the clipboard
|
|
||||||
# $ clip | python3 # runs what's in the clipboard using python3
|
|
||||||
|
|
||||||
# make and cd into directory
|
|
||||||
into() {
|
|
||||||
mkdir -p "$1" && cd "$1";
|
|
||||||
}
|
|
||||||
|
|
||||||
# make a new terminal
|
|
||||||
split() {
|
|
||||||
(kitty . &)
|
|
||||||
}
|
|
||||||
|
|
||||||
APPLETS=("svelte" "react" "vite")
|
|
||||||
|
|
||||||
declare -A KNOWN_APPLETS=(
|
|
||||||
["svelte"]="npm create svelte@latest"
|
|
||||||
["react"]="npx create-next-app@latest"
|
|
||||||
["vite"]="npm create vite@latest"
|
|
||||||
)
|
|
||||||
|
|
||||||
create() {
|
|
||||||
if [[ -n "$KNOWN_APPLETS[$1]" ]]; then
|
|
||||||
eval "$KNOWN_APPLETS[$1]"
|
|
||||||
else
|
|
||||||
echo "$fg[red]FATAL:$fg[white] I don't know that applet"
|
|
||||||
echo "USAGE: create <applet>"
|
|
||||||
echo "APPLETS:"
|
|
||||||
echo " $APPLETS"
|
|
||||||
return 64
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# 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
|
|
||||||
|
|
||||||
136
zsh/prompt.sh
136
zsh/prompt.sh
@@ -1,136 +0,0 @@
|
|||||||
# 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]%}:"
|
|
||||||
if [[ -n "$(git remote show)" ]]; then
|
|
||||||
PROMPT+="%{$fg[yellow]%}$(git remote show | head -n 1)"
|
|
||||||
else
|
|
||||||
PROMPT+="%{$fg_bold[red]%}NO-REMOTE"
|
|
||||||
fi
|
|
||||||
PROMPT+=" %{$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