if test -f /usr/share/doc/fzf/examples/completion.zsh &> /dev/null; then source /usr/share/doc/fzf/examples/completion.zsh fi ssh_ids=$(find "$HOME/.ssh" -type f -name "id*" | grep -v '\.pub') if [[ "$ssh_ids" != "" ]]; then eval "$(ssh-agent -s)" &> /dev/null for id in $(echo $ssh_ids); do ssh-add "$id" &> /dev/null done fi HISTFILE=~/.histfile HISTSIZE=SAVEHIST=100000000 setopt appendhistory autocd notify setopt menu_complete unsetopt beep bindkey -v autoload -Uz up-line-or-beginning-search autoload -Uz down-line-or-beginning-search zle -N up-line-or-beginning-search zle -N down-line-or-beginning-search bindkey '\eOA' up-line-or-beginning-search bindkey '\e[A' up-line-or-beginning-search bindkey '\eOB' down-line-or-beginning-search bindkey '\e[B' down-line-or-beginning-search export EDITOR="vim" zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate zstyle ':completion:*' matcher-list '+' '+m:{[:lower:]}={[:upper:]}' '+m:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+r:|[._-]=** r:|=** l:|=*' zstyle :compinstall filename '~/.zshrc' zstyle ':completion:*' ignored-patterns '*.class' autoload -Uz compinit compinit # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi export PATH=~/.bin:$HOME/.dotnet:~/.local/bin:/usr/local/go/bin:$PATH fignore=(o class swp) function SetTtyColors() { echo -en "\e]P0""2c2d27" # black 1 echo -en "\e]P1""f92672" # darkgrey 2 echo -en "\e]P2""00aa00" # darkred 3 echo -en "\e]P3""f92672" # red 4 echo -en "\e]P4""4444aa" # darkgreen 5 echo -en "\e]P5""a6e22e" # green 6 echo -en "\e]P6""f59762" # brown 7 echo -en "\e]P7""fdfff1" # yellow 8 echo -en "\e]P8""f92672" # darkblue 9 echo -en "\e]P9""f92672" # blue 10 echo -en "\e]PA""55ff55" # darkmagenta 11 echo -en "\e]PB""f92672" # magenta 12 echo -en "\e]PC""66d9ef" # darkcyan 13 echo -en "\e]PD""ae81ff" # cyan 14 echo -en "\e]PE""a1efe4" # lightgray 15 echo -en "\e]PF""fdfff1" # white 16 clear } if [ "$TERM" = "linux" ]; then SetTtyColors fi source ~/.shell_aliases source ~/.zsh_local SYNC_LOCK_FILE="$HOME/.sync-lock" # Ignores certain values/sections that shouldn't be synced function dconf-clean { local current_section="" local ignore_section=false cat "$1" | while read -r line; do if [[ "$line" == "["* ]]; then current_section="$line" ignore_section=false elif [[ "$line" == "']" ]]; then current_section="$line" ignore_section=true fi case "$current_section" in "[org/gnome/desktop/background]" | \ "[org/gnome/gedit/state/history-entry]" | \ "[org/gnome/gedit/plugins/filebrowser]" | \ "[org/gnome/desktop/notifications]" | \ "[org/gnome/cheese]" | \ "[org/gnome/shell/extensions/gsconnect"*) ignore_section=true ;; "[org/gnome/desktop/interface]") if [[ "$line" == "gtk-theme='"* ]]; then continue fi echo "$line" ;; *) if ! $ignore_section; then echo "$line" fi ;; esac done } function dconf-dump { dconf dump / > "$HOME/.dconf-dump.tmp" } function push-dconf { if ! command -v dconf &> /dev/null; then echo "The current system does not include dconf" return fi if ! command -v scpace &> /dev/null; then echo "An alias for scpace has not been defined on this device!" return 1 fi dconf-dump > $HOME/.tmp/dconf-dump || return 1 scp -P 11275 $HOME/.tmp/dconf-dump 'sage@sagev.space:~/dconf-dump' } function push-extensions { if ! command -v gnome-extensions &> /dev/null; then echo "gnome-extensions is not installed!" return fi mv $HOME/.tmp/gnome-extension-list "$HOME/.tmp/prev-gnome-extension-list" &> /dev/null gnome-extensions list --enabled > "$HOME/.tmp/gnome-extension-list" # If there is NO difference, skip scp if [[ "$1" != "--force" ]] && diff "$HOME/.tmp/gnome-extension-list" "$HOME/.tmp/prev-gnome-extension-list" &> /dev/null; then return fi scp -P 11275 "$HOME/.tmp/gnome-extension-list" 'sage@sagev.space:~/gnome-extension-list' } function merge-hist { \diff --unified=9999999999999999 "$1" "$2" | tail -n +4 | sed 's/^.//' } function sync-history { echo "Downloading shared history..." if ! scp -P 11275 'sage@sagev.space:~/histfile' "$HOME/.tmp/.histfile"; then echo "Shared history download failed!" scp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile' return fi echo "Merging history files..." fc -W # Write to history file merge-hist "$HOME/.histfile" "$HOME/.tmp/.histfile" > "$HOME/.tmp/$(whoami).histfile" mv "$HOME/.tmp/$(whoami).histfile" "$HOME/.histfile" fc -R # Read from new history file echo "Uploading new shared history..." scp -P 11275 "$HOME/.histfile" 'sage@sagev.space:~/histfile' } function install-extension { local ext="$1" local file="$1.zip" if ! gnome-extensions install --force ${ext}.zip; then return 1 fi if ! gnome-extensions list | grep --quiet ${ext}; then if ! busctl --user call org.gnome.Shell.Extensions /org/gnome/Shell/Extensions org.gnome.Shell.Extensions InstallRemoteExtension s ${ext}; then return 1 fi fi gnome-extensions enable ${ext} } function load-extensions { if ! command -v gnome-extensions &> /dev/null; then echo "gnome-extensions is not installed!" return fi scp -P 11275 'sage@sagev.space:~/gnome-extension-list' $HOME/.tmp/gnome-extension-list touch "$HOME/.unavailable-extensions" local existing="$(cat <(gnome-extensions list) "$HOME/.unavailable-extensions")" for ext in $(cat $HOME/.tmp/gnome-extension-list); do if grep "$ext" <(echo $existing) &> /dev/null; then continue fi VERSION_TAG=$(curl -Lfs "https://extensions.gnome.org/extension-query/?search=${ext}" | jq '.extensions[0] | .shell_version_map | map(.pk) | max') if ! wget -O ${ext}.zip "https://extensions.gnome.org/download-extension/${ext}.shell-extension.zip?version_tag=$VERSION_TAG"; then echo "$ext" >> "$HOME/.unavailable-extensions" continue fi if ! install-extension "$ext"; then echo "$ext" >> "$HOME/.unavailable-extensions" fi rm ${ext}.zip done } function lock-wait { local file="$1" local seconds="$2" local action="$3" if test -f "$file"; then echo "Sync lockfile present at '$file'" echo "Watching its output:" tail -f "$file" & tail_pid=$! [[ "$action" == "" ]] || echo "Waiting for $action to finish" for i in {0..$seconds}; do sleep 1 if ! test -f "$file"; then kill $tail_pid &> /dev/null echo echo "Lock file at '$file' freed." echo break fi done fi } function lockfor { local file="$1" local seconds="$2" lock-wait "$file" "$seconds" touch "$file" $3 $4 $5 $6 $7 $8 $9 $10 rm "$file" } function dot-lock-wait { lock-wait "$SYNC_LOCK_FILE" 90 "Waiting for ongoing sync to finish" } function _pushdot { cd "$DOT_DIR" || return 1 local res if ! git diff --quiet; then if [ $# -eq 0 ]; then git commit -a res="$?" else git commit -a -m "$@" res="$?" fi if [[ "$res" == "0" ]]; then git push -u origin main fi fi push-extensions | tee -a "$SYNC_LOCK_FILE" sync-history | tee -a "$SYNC_LOCK_FILE" push-dconf | tee -a "$SYNC_LOCK_FILE" cd - return $res } function pushdot { lockfor "$SYNC_LOCK_FILE" 90 _pushdot $@ } function sync-dconf { if ! command -v dconf &> /dev/null; then echo "System does not use dconf" return fi rm $HOME/.tmp/dconf-dump &> /dev/null scp -P 11275 'sage@sagev.space:~/dconf-dump' $HOME/.tmp/dconf-dump-inbound dconf-clean $HOME/.tmp/dconf-dump-inbound > $HOME/.tmp/dconf-dump dconf-dump > $HOME/.tmp/current-dconf-dump if ! git --no-pager diff --no-index $HOME/.tmp/current-dconf-dump $HOME/.tmp/dconf-dump &> /dev/null; then echo echo "Incoming conf changes:" echo git --no-pager diff --no-index $HOME/.tmp/current-dconf-dump $HOME/.tmp/dconf-dump echo bash -c 'read -p "Press enter to continue, or Ctrl-C to cancel."' || return 1 echo "Applying changes..." fi dconf load / < $HOME/.tmp/dconf-dump || return 1 push-dconf } function _getdot { if ! command -v scpace &> /dev/null; then echo "An alias for scpace has not been defined on this device!" return 1 fi dot-lock-wait cd "$DOT_DIR" || return 1 git pull && ./copy.sh | tee -a "$SYNC_LOCK_FILE" sync-history | tee -a "$SYNC_LOCK_FILE" load-extensions | tee -a "$SYNC_LOCK_FILE" [[ "$1" != "--skip-dconf" ]] && sync-dconf | tee -a "$SYNC_LOCK_FILE" cd - > /dev/null } function getdot { lockfor "$SYNC_LOCK_FILE" 90 _getdot $@ } if which starship &> /dev/null; then eval "$(starship init zsh)" fi last_get_file="$HOME/.tmp/.$(whoami)-dotfiles-last-get" current_date="$(date '+%Y-%m-%d')" if [[ "$RUN_GETDOT" == "true" ]] || (test -d "$DOT_DIR" && [[ "$current_date" != "$(cat "$last_get_file")" ]] &> /dev/null); then echo "$current_date" > "$last_get_file" date >> "$HOME/.tmp/getdot-log" getdot $GETDOT_ARGS >> "$HOME/.tmp/getdot-log" echo >> "$HOME/.tmp/getdot-log" fi export nvm_loaded=false alias nvm="load_nvm; nvm" alias npm="load_nvm; npm" alias node="load_nvm; node" alias standard="load_nvm; standard" alias lf="load_nvm; standard --fix" function load_nvm { if $nvm_loaded; then return fi unalias nvm unalias node export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion export nvm_loaded=true } test -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh && source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh test -f "$HOME/.asdf/asdf.sh" && . "$HOME/.asdf/asdf.sh" test -f ~/.cargo/env && source ~/.cargo/env # bun completions [ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun" # bun export BUN_INSTALL="$HOME/.bun" export PATH="$BUN_INSTALL/bin:$PATH"