Skip to content

Instantly share code, notes, and snippets.

@vlrmprjct
Last active February 5, 2024 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlrmprjct/98cdfcdd25c83edddec08955b7472b09 to your computer and use it in GitHub Desktop.
Save vlrmprjct/98cdfcdd25c83edddec08955b7472b09 to your computer and use it in GitHub Desktop.
OhMyZSH Custom Configuration
# path needs to be set before oh-my-zsh is loaded
export PATH=~/.npm-global/bin:$PATH
export PATH=~/.npm/bin:$PATH
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
export PATH=$PATH:"/home/thomas/bin"
export NVM_DIR="$HOME/.nvm"
# load nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# load nvm bash_completion
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# oh-my-zsh install path
export ZSH="./.oh-my-zsh"
# see oh-my-zsh custom directory
# oh-my-zsh config
ZSH_THEME="custom"
DISABLE_UNTRACKED_FILES_DIRTY="true"
plugins=(git emoji-clock web-search)
# oh-my-zsh execution
source $ZSH/oh-my-zsh.sh
# oh my zsh personal aliases
# ~/.oh-my-zsh/custom/aliases.zsh
# git
# See oh-my-zsh plugins @ .zshrc
alias gfp='git fetch && git pull'
# user
alias clip="clip.exe"
alias paste="powershell.exe Get-Clipboard"
alias pwgen="date +%s | sha256sum | base64 | head -c12 | clip | paste && echo 'PW copied to clipboard!'"
alias wslconfig="sudo nano /etc/wsl.conf"
alias zshconfig="nano ~/.zshrc"
alias wttr="curl -s 'https://en.wttr.in/dresden\?0Q'"
alias ipinfo="curl -s https://ipinfo.io/ip"
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias lh='ls -hal'
# dir aliases
alias prj='cd /d/Projects/'
alias pia='cd /d/Projects/pia/'
alias bill='cd /d/Projects/billomat/'
alias fe='cd /d/Projects/billomat/billomat-projects/packages/billomat-frontend/'
alias ui='cd /d/Projects/billomat/billomat-ui-ts/'
alias uiicn='cd /d/Projects/billomat/billomat-ui-iconset/'
alias gql='cd /d/Projects/billomat/billomat-projects/packages/billograph/'
# node
alias nj='node'
# npm start aliases
alias fes="fe && nvm use && npm start"
alias uits="uits && nvm use && npm start"
alias gqls="gql && npm run start:local"
# oh my zsh custom theme
# based on robbyrussel.zsh-theme
# ~/.oh-my-zsh/custom/themes/custom.zsh-theme
# PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
PROMPT="%(?:%{$fg[green]%}➜ :%{$fg[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[magenta]%}git:(%{$fg[cyan]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}*"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[magenta]%})"
# oh my zsh welcome message
# ~/.oh-my-zsh/custom/message.zsh
# Define a file to store the last display time
last_display_file=$(dirname $0)/message_delay
# Function to check if an hour has passed since the last display
should_display() {
local last_display
if [ -e "$last_display_file" ]; then
last_display=$(cat "$last_display_file")
else
# If the file doesn't exist, display the message
return 0
fi
local current_time=$(date +%s)
local one_hour=3600
# Check if an hour has passed
if ((current_time - last_display > one_hour)); then
return 0
else
return 1
fi
}
# Function to update the last display timestamp
update_last_display() {
date +%s > "$last_display_file"
}
quota() {
local mount_point="$1"
local value_type="$2"
local total=$(df -BG "$mount_point" | awk 'NR==2{print $2}' | cut -d'G' -f1)
local used=$(df -BG "$mount_point" | awk 'NR==2{print $3}' | cut -d'G' -f1)
local free=$(df -BG "$mount_point" | awk 'NR==2{print $4}' | cut -d'G' -f1)
local percent=$(echo "scale=2; 100 - $free / $total * 100" | bc)
local -A values
values=([total]="$total"
[used]="$used"
[free]="$free"
[percent]="$percent")
echo "${values[$value_type]}"
}
bargraph() {
local mount_point="$1"
total_segments=20
used_segments=$(echo "scale=0; $(quota $1 "percent") / 5" | bc)
bar_graph=""
for ((i=1; i<=total_segments; i++)); do
if [ "$i" -le "$used_segments" ]; then
bar_graph+="█"
else
bar_graph+="▄"
fi
done
echo -e "$bar_graph"
}
message() {
echo -e " $fg[magenta]Welcome to WSL$reset_color (GNU/Linux $(uname -r))"
echo
echo -e " $fg[magenta]You:$reset_color $fg[cyan]$(whoami)@$(hostname)$reset_color"
echo -e " $fg[magenta]Date:$reset_color $fg[cyan]$(date +"%A, %B %d, %Y %I:%M %p")$reset_color"
echo -e " $fg[magenta]Uptime:$reset_color Host up for $fg[cyan]$(uptime -p)$reset_color"
echo
echo -e " $fg[magenta]Load:$reset_color $fg[cyan]$(uptime | awk -F'load average: ' '{print $2}')$reset_color"
echo -e " $fg[magenta]Processes:$reset_color $fg[cyan]$(ps aux | wc -l)$reset_color"
echo -e " $fg[magenta]Quota C:$reset_color Used $fg[cyan]$(quota "/c" "used") GB$reset_color of $fg[cyan]$(quota "/c" "total") GB$reset_color ($fg[cyan]$(quota "/c" "percent")%$reset_color) \t$fg[cyan]$(bargraph "/c")$reset_color"
echo -e " $fg[magenta]Quota D:$reset_color Used $fg[cyan]$(quota "/d" "used") GB$reset_color of $fg[cyan]$(quota "/d" "total") GB$reset_color ($fg[cyan]$(quota "/d" "percent")%$reset_color) \t$fg[cyan]$(bargraph "/d")$reset_color"
echo -e " $fg[magenta]RAM:$reset_color $fg[cyan]$(free --mega | awk 'NR==2{print $3}') MB$reset_color used ($fg[cyan]$(free --mega | awk 'NR==2{print $3/$2*100}')%$reset_color)"
echo -e " $fg[magenta]IP:$reset_color $fg[cyan]$(curl -s https://ipinfo.io/ip)$reset_color / $fg[cyan]$(ip addr show wifi0 | grep 'inet ' | awk '{print $2}')$reset_color"
echo
echo -e " $fg[magenta]ZSH:$reset_color $(zsh --version)"
echo -e " $fg[magenta]NODE:$reset_color $(node --version | cut -c 2-)"
echo -e " $fg[magenta]NPM:$reset_color $(npm --version)"
echo
}
# Check if an hour has passed since the last display
if should_display; then
message
# Update the last display timestamp
update_last_display
fi
# Autoload the function to make it available as a command
autoload -Uz message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment