Last active
December 27, 2023 22:23
-
-
Save ben-kenney/b3a88840f24d5ed78248d3c831488c16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# some parts borrowed from | |
# http://leahneukirchen.org/dotfiles/.zshrc | |
# https://leahneukirchen.org/blog/archive/2012/02/10-new-zsh-tricks-you-may-not-know.html | |
# these options allow for neat directory history | |
# cd -<TAB> | |
setopt AUTO_PUSHD | |
setopt PUSHD_IGNORE_DUPS | |
setopt PUSHD_MINUS | |
# Path to your oh-my-zsh configuration. | |
ZSH=$HOME/.oh-my-zsh | |
# Set name of the theme to load. | |
# Look in ~/.oh-my-zsh/themes/ | |
# Optionally, if you set this to "random", it'll load a random theme each | |
# time that oh-my-zsh is loaded. | |
#ZSH_THEME="robbyrussell" | |
#ZSH_THEME="gallois" | |
ZSH_THEME="benk" | |
# Example aliases | |
# alias zshconfig="mate ~/.zshrc" | |
# alias ohmyzsh="mate ~/.oh-my-zsh" | |
# Set to this to use case-sensitive completion | |
# CASE_SENSITIVE="true" | |
# Uncomment this to disable bi-weekly auto-update checks | |
# DISABLE_AUTO_UPDATE="true" | |
DISABLE_UPDATE_PROMPT=true | |
# Uncomment to change how often before auto-updates occur? (in days) | |
# export UPDATE_ZSH_DAYS=13 | |
# Uncomment following line if you want to disable colors in ls | |
# DISABLE_LS_COLORS="true" | |
# Uncomment following line if you want to disable autosetting terminal title. | |
# DISABLE_AUTO_TITLE="true" | |
# Uncomment following line if you want to disable command autocorrection | |
# DISABLE_CORRECTION="true" | |
# Uncomment following line if you want red dots to be displayed while waiting for completion | |
COMPLETION_WAITING_DOTS="true" | |
# Uncomment following line if you want to disable marking untracked files under | |
# VCS as dirty. This makes repository status check for large repositories much, | |
# much faster. | |
# DISABLE_UNTRACKED_FILES_DIRTY="true" | |
# Uncomment following line if you want to shown in the command execution time stamp | |
# in the history command output. The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"| | |
# yyyy-mm-dd | |
HIST_STAMPS="mm/dd/yyyy" | |
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) | |
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ | |
# Example format: plugins=(rails git textmate ruby lighthouse) | |
# Note: zsh-syntax-highlighting must come last in the plugins list | |
#plugins=(git osx rsync python cp brew history web-search zsh-syntax-highlighting z) | |
plugins=(git rsync python cp history web-search z zsh-autosuggestions zsh-syntax-highlighting) | |
# custom addons | |
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) | |
ZSH_HIGHLIGHT_PATTERNS=('rm -rf *' 'fg=white,bold,bg=red') | |
setopt RM_STAR_WAIT #This will add a 10 second wait before you can confirm a wildcard deletion | |
export HISTSIZE=32768; | |
export HISTFILESIZE=$HISTSIZE; | |
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"; | |
#bindkey "^[[A" history-beginning-search-backward-end | |
#bindkey "^[[B" history-beginning-search-forward-end | |
# cursor will disaper without this | |
typeset -A ZSH_HIGHLIGHT_STYLES | |
ZSH_HIGHLIGHT_STYLES[cursor]=underline | |
# historical backward/forward search with linehead string binded to ^P/^N | |
autoload history-search-end | |
zle -N history-beginning-search-backward-end history-search-end | |
zle -N history-beginning-search-forward-end history-search-end | |
bindkey "^p" history-beginning-search-backward-end | |
bindkey "^n" history-beginning-search-forward-end | |
bindkey "\\ep" history-beginning-search-backward-end | |
bindkey "\\en" history-beginning-search-forward-end | |
source $ZSH/oh-my-zsh.sh | |
##################################### | |
# User configuration | |
##################################### | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxCxDxBxegedabagacad | |
# # Preferred editor for local and remote sessions | |
# if [[ -n $SSH_CONNECTION ]]; then | |
# export EDITOR='nano' | |
# else | |
# export EDITOR='vim' | |
# fi | |
# Compilation flags | |
# export ARCHFLAGS="-arch x86_64" | |
# ssh | |
# export SSH_KEY_PATH="~/.ssh/dsa_id" | |
# list most recent directories with 'd' | |
# then chd by typing '$ cd -N' where N is the index from 'd' | |
# Usage: cd -2 | |
# Can also use cd -<TAB> | |
DIRSTACKSIZE=9 | |
DIRSTACKFILE=~/.zdirs | |
if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then | |
dirstack=( ${(f)"$(< $DIRSTACKFILE)"} ) | |
[[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD | |
fi | |
chpwd() { | |
print -l $PWD ${(u)dirstack} >$DIRSTACKFILE | |
} | |
##################################### | |
# Custom functions | |
##################################### | |
# toggle the sshfs mounts | |
# usage: toggle_mount <server> <mount point> | |
# assumes the local mount is /mnt/droplet_<server> | |
toggle_sshfs () { | |
# arguments: | |
# $1 the server name in ~/.ssh/config. Either CT101 or ebudgie | |
# $2 the mount point on the server. ebudgie -> /media/droplet or CT101 -> /home/ben | |
# $3 the name of the local directory in ~/Droplets/droplet_$3 | |
mnt="/home/$USER/Droplets/droplet_$3" | |
mkdir -p $mnt | |
if mountpoint -q "$mnt"; then | |
echo "unmounting $mnt" | |
sudo umount "$mnt" | |
else | |
echo "mounting $mnt" | |
[ ! -d "$mnt" ] && sudo mkdir "$mnt" && sudo chown ben:ben "$mnt" | |
sshfs -o allow_other,default_permissions $USER@$1:$2 $mnt | |
fi | |
} | |
toggle_rclone () { | |
# arguments: | |
# $1 the server name for rclone: ex: onedrive | |
mnt="/home/$USER/Droplets/droplet_$1" | |
is_mounted=$(df -h | grep $1 | wc -l) | |
if [[ $is_mounted -gt 0 ]]; then | |
echo "umounting $mnt" | |
fusermount -u $mnt | |
else | |
echo "mounting $mnt" | |
[ ! -d "$mnt" ] && sudo mkdir "$mnt" && sudo chown ben:ben "$mnt" | |
rclone mount --vfs-cache-mode full --daemon $1: $mnt | |
fi | |
} | |
# mount droplets using sshfs and rclones | |
mntdroplets () { | |
# mount droplets | |
# currently configured for CT101 and ebudgie | |
#toggle_mount "CT101" "/home/ben" | |
#toggle_mount "ebudgie" "/media/droplet" | |
toggle_sshfs "hetznerarm" "/home/ben" "hetznerarm" | |
toggle_sshfs "proxmox" "/mnt/WDInternalSSD500GB" "WDSSD500GB" | |
toggle_sshfs "proxmox" "/mnt/pve" "pve" | |
toggle_rclone "onedrive" | |
toggle_rclone "s3" | |
} | |
# use rsync to copy files | |
# Usage: cpr source_file destination_file | |
cpr () { | |
rsync -avh --progress "$1" "$2" | |
} | |
# find all files in current dir or subdirs with "text" in the file | |
# Usage: ftext "text" | |
ftext () { | |
grep -iIHrn --color=always "$1" . | less -R -r | |
} | |
# find duplicate files | |
# Usage: duplocatefind | |
duplicatefind () | |
{ | |
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate | |
} | |
# generate QR code for the string | |
# Usage: gnerateqr "string to convert to QR" | |
generateqr () | |
{ | |
printf "$@" | curl -F-=\<- qrenco.de | |
} | |
# change directory and list | |
# Usage: cdl directory | |
cdl () | |
{ | |
cd "$1" && ls -lht | |
} | |
# send a message to ntfy | |
quick_ntfy () | |
{ | |
curl -H "Title: Quick share from $(hostname)" -H "Authorization: Bearer tk_bbi70lczkpztxul5pbgw5gwlx8a7w" -H "Markdown: yes" -d "${1}" https://ntfy.096485.xyz/bak-general | |
} | |
# create a new tmux terminal with argument as name | |
# ex: ntmux ebud | |
ntmux () | |
{ | |
tmux new -s ${1} | |
} | |
# ssh into a machine using the tailscale ip address | |
# as is this only works on WSL with Tailscale installed in windows | |
# tailssh debudgie -> ssh -i ~/.ssh/personal_key 100.xx.xx.xx | |
tailssh () | |
{ | |
ssh -i ~/.ssh/personal_key $(tailscale.exe status | grep "${1}" | awk '{print $1}') | |
} | |
##################################### | |
# Aliases | |
##################################### | |
#global alias to keep a log from a command | |
alias -g wlog='2>&1 | tee log' #example: ./app.py wlog | |
# get a list of top 20 files/folders | |
alias ddu='du -sh * | sort -hr | head -20' | |
# use .. instead of cd .. | |
alias ..='cd .. && ls' | |
# open a window from the command line in linux | |
alias ow='xdg-open .' | |
# use less with line numbers instead of more | |
# other tricks with less: less -N +/error file.txt will open file at first occurence of error | |
# alias more='less -N' | |
# use nano as default editor when pressive `v` in less | |
export EDITOR='nano' | |
export VISUAL='nano' | |
##################################### | |
# Python paths | |
##################################### | |
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh | |
export FZF_DEFAULT_OPS="--extended" | |
# >>> conda initialize >>> | |
# !! Contents within this block are managed by 'conda init' !! | |
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" | |
if [ $? -eq 0 ]; then | |
eval "$__conda_setup" | |
else | |
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then | |
. "$HOME/miniconda3/etc/profile.d/conda.sh" | |
else | |
export PATH="$HOME/miniconda3/bin:$PATH" | |
fi | |
fi | |
unset __conda_setup | |
# <<< conda initialize <<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment