commit 0f5ec45ccb2f1f95caa6fbf5ad2ba2c081495691 Author: Antonin Ruan Date: Sat Oct 5 19:14:59 2024 -1000 Config files for zsh diff --git a/.p10k.omp.yml b/.p10k.omp.yml new file mode 100644 index 0000000..3ab0db4 --- /dev/null +++ b/.p10k.omp.yml @@ -0,0 +1,121 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json + +version: 2 +blocks: +- type: prompt + alignment: left + newline: true + segments: + - type: text + style: plain + template: ╭─ + foreground: "#585858" + + - type: os + style: plain + template: " {{ if .WSL }}WSL at {{ end }}{{.Icon}} " + background: "#303030" + foreground: "#26C6DA" + + - type: text + style: plain + template:  + background: parentBackground + foreground: "#8a8a8a" + + - type: path + style: plain + template: ' {{ if eq .PWD "~" }} {{ else }} {{ end }}{{ .Parent }}' + background: parentBackground + foreground: "#0087af" + + - type: path + style: plain + template: "{{ .Path }} " + properties: + style: folder + background: parentBackground + foreground: "#00afff" + + - type: git + style: plain + template: "<#8a8a8a> {{ if .UpstreamIcon}}{{ .UpstreamIcon }}{{ else }} {{ end }}{{ .HEAD }}{{ if .Working.Changed }} <#00afff>{{ .Working.String }}{{ end }} " + background: parentBackground + foreground: "#5fd700" + properties: + branch_icon: "" + git_icon: " " + github_icon: " " + gitlab_icon: " " + fetch_upstream_icon: true + fetch_status: true + + - type: text + style: plain + template:  + background: transparent + foreground: parentBackground + +- type: prompt + alignment: right + filler: "<#585858>-" + segments: + - type: text + style: plain + template: "" + background: transparent + foreground: parentForeground + + - type: status + style: plain + template: " {{ if eq .Code 0 }}<#5faf00>✔{{ else }}{{.String}} ✘{{ end }}" + background: parentForeground + foreground: "#d70000" + properties: + always_enabled: true + + - type: python + style: plain + template: " <#8a8a8a> {{ .Venv }} " + background: parentBackground + foreground: "#00afaf" + properties: + fetch_virtual_env: true + display_mode: environment + + - type: executiontime + style: plain + template: " <#8a8a8a> {{ .FormattedMs }} " + background: parentBackground + foreground: "#a8a8a8" + properties: + style: round + + - type: time + style: plain + template: " <#8a8a8a> {{ .CurrentDate | date .Format }} \uf017 " + properties: + time_format: "15:04:05" + background: parentBackground + foreground: "#5f8787" + + - type: text + style: plain + template: "─╮" + background: transparent + foreground: "#585858" + +- type: prompt + alignment: left + segments: + - type: text + style: plain + foreground: "#585858" + template: "╰─ " + newline: true +- type: rprompt + segments: + - type: text + style: plain + foreground: "#585858" + template: "─╯" diff --git a/.zsh/colors.zsh b/.zsh/colors.zsh new file mode 100644 index 0000000..0e5a503 --- /dev/null +++ b/.zsh/colors.zsh @@ -0,0 +1,63 @@ +# Use diff --color if available +if command diff --color /dev/null{,} &>/dev/null; then + function diff { + command diff --color "$@" + } +fi + +# Default coloring for BSD-based ls +export LSCOLORS="Gxfxcxdxbxegedabagacad" + +# Default coloring for GNU-based ls +if [[ -z "$LS_COLORS" ]]; then + # Define LS_COLORS via dircolors if available. Otherwise, set a default + # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors) + if (( $+commands[dircolors] )); then + [[ -f "$HOME/.dircolors" ]] \ + && source <(dircolors -b "$HOME/.dircolors") \ + || source <(dircolors -b) + else + export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" + fi +fi + +function test-ls-args { + local cmd="$1" # ls, gls, colorls, ... + local args="${@[2,-1]}" # arguments except the first one + command "$cmd" "$args" /dev/null &>/dev/null +} + +# Find the option for using colors in ls, depending on the version +case "$OSTYPE" in + netbsd*) + # On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors); + # otherwise, leave ls as is, because NetBSD's ls doesn't support -G + test-ls-args gls --color && alias ls='gls --color=tty' + ;; + openbsd*) + # On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base, + # with color and multibyte support) are available from ports. + # `colorls` will be installed on purpose and can't be pulled in by installing + # coreutils (which might be installed for ), so prefer it to `gls`. + test-ls-args gls --color && alias ls='gls --color=tty' + test-ls-args colorls -G && alias ls='colorls -G' + ;; + (darwin|freebsd)*) + # This alias works by default just using $LSCOLORS + test-ls-args ls -G && alias ls='ls -G' + # Only use GNU ls if installed and there are user defaults for $LS_COLORS, + # as the default coloring scheme is not very pretty + zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \ + && test-ls-args gls --color \ + && alias ls='gls --color=tty' + ;; + *) + if test-ls-args ls --color; then + alias ls='ls --color=tty' + elif test-ls-args ls -G; then + alias ls='ls -G' + fi + ;; +esac + +unfunction test-ls-args diff --git a/.zsh/keybinds.zsh b/.zsh/keybinds.zsh new file mode 100644 index 0000000..d29182c --- /dev/null +++ b/.zsh/keybinds.zsh @@ -0,0 +1,106 @@ +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets + +# Make sure that the terminal is in application mode when zle is active, since +# only then values from $terminfo are valid +if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then + function zle-line-init() { + echoti smkx + } + function zle-line-finish() { + echoti rmkx + } + zle -N zle-line-init + zle -N zle-line-finish +fi + +# Use emacs key bindings +bindkey -e + +# Start typing + [Up-Arrow] - fuzzy find history forward +autoload -U up-line-or-beginning-search +zle -N up-line-or-beginning-search + +bindkey -M emacs "^[[A" up-line-or-beginning-search +bindkey -M viins "^[[A" up-line-or-beginning-search +bindkey -M vicmd "^[[A" up-line-or-beginning-search +if [[ -n "${terminfo[kcuu1]}" ]]; then + bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search + bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search + bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search +fi + +# Start typing + [Down-Arrow] - fuzzy find history backward +autoload -U down-line-or-beginning-search +zle -N down-line-or-beginning-search + +bindkey -M emacs "^[[B" down-line-or-beginning-search +bindkey -M viins "^[[B" down-line-or-beginning-search +bindkey -M vicmd "^[[B" down-line-or-beginning-search +if [[ -n "${terminfo[kcud1]}" ]]; then + bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search + bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search + bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search +fi + +# [Home] - Go to beginning of line +if [[ -n "${terminfo[khome]}" ]]; then + bindkey -M emacs "${terminfo[khome]}" beginning-of-line + bindkey -M viins "${terminfo[khome]}" beginning-of-line + bindkey -M vicmd "${terminfo[khome]}" beginning-of-line +fi +# [End] - Go to end of line +if [[ -n "${terminfo[kend]}" ]]; then + bindkey -M emacs "${terminfo[kend]}" end-of-line + bindkey -M viins "${terminfo[kend]}" end-of-line + bindkey -M vicmd "${terminfo[kend]}" end-of-line +fi + +# [Shift-Tab] - move through the completion menu backwards +if [[ -n "${terminfo[kcbt]}" ]]; then + bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete + bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete + bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete +fi + +# [Backspace] - delete backward +bindkey -M emacs '^?' backward-delete-char +bindkey -M viins '^?' backward-delete-char +bindkey -M vicmd '^?' backward-delete-char +# [Delete] - delete forward +if [[ -n "${terminfo[kdch1]}" ]]; then + bindkey -M emacs "${terminfo[kdch1]}" delete-char + bindkey -M viins "${terminfo[kdch1]}" delete-char + bindkey -M vicmd "${terminfo[kdch1]}" delete-char +else + bindkey -M emacs "^[[3~" delete-char + bindkey -M viins "^[[3~" delete-char + bindkey -M vicmd "^[[3~" delete-char + + bindkey -M emacs "^[3;5~" delete-char + bindkey -M viins "^[3;5~" delete-char + bindkey -M vicmd "^[3;5~" delete-char +fi + +# [Ctrl-Delete] - delete whole forward-word +bindkey -M emacs '^[[3;5~' kill-word +bindkey -M viins '^[[3;5~' kill-word +bindkey -M vicmd '^[[3;5~' kill-word + +# [Ctrl-RightArrow] - move forward one word +bindkey -M emacs '^[[1;5C' forward-word +bindkey -M viins '^[[1;5C' forward-word +bindkey -M vicmd '^[[1;5C' forward-word +# [Ctrl-LeftArrow] - move backward one word +bindkey -M emacs '^[[1;5D' backward-word +bindkey -M viins '^[[1;5D' backward-word +bindkey -M vicmd '^[[1;5D' backward-word + + +bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. + +# Edit the current command line in $EDITOR +autoload -U edit-command-line +zle -N edit-command-line +bindkey '\C-x\C-e' edit-command-line diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..eb5a54e --- /dev/null +++ b/.zshrc @@ -0,0 +1,58 @@ +ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" + +# Automatically download zinit +if [ ! -d "$ZINIT_HOME" ]; then + mkdir -p "$(dirname $ZINIT_HOME)" + git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" +fi + +source "${ZINIT_HOME}/zinit.zsh" + +# Plugins + +zinit light zsh-users/zsh-syntax-highlighting +zinit light zsh-users/zsh-completions +zinit light zsh-users/zsh-autosuggestions +zinit light Aloxaf/fzf-tab + +zinit snippet OMZP::git +zinit snippet OMZP::sudo + +source ~/.zsh/keybinds.zsh +source ~/.zsh/colors.zsh + +# Load completions +autoload -U compinit && compinit +zinit cdreplay -q + +# History +HISTSIZE=5000 +HISTFILE=~/.zsh_history +SAVEHIST=10000 +setopt share_history +setopt hist_ignore_space +setopt extended_history +setopt hist_expire_dups_first +setopt hist_ignore_dups +setopt hist_verify + +# Completion +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' special-dirs true +zstyle ':completion:*' menu no +zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath' +zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories +zstyle ':completion:*' use-cache yes +zstyle ':completion:*' cache-path $ZSH_CACHE_DIR + +setopt auto_menu +setopt complete_in_word +setopt always_to_end +setopt autocd + +# Aliases +source ~/.aliases + +eval "$(fzf --zsh)" +eval "$(oh-my-posh init zsh --config '~/.p10k.omp.yml')" diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..0e18540 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +.emacs|symlink| +.emacs.local|symlink| +.emacs.rc|symlink| +.config/kitty|symlink| +.config/starship.toml|symlink| +.zshrc|symlink| +.p10k.omp.yml|symlink| +.zsh|symlink| +.aliases|symlink| \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..1ab9eb0 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )" + +symlinkFile() { + filename="$SCRIPT_DIR/$1" + destination="$HOME/$2/$1" + + mkdir -p $(dirname "$destination") + + if [ -L "$destination" ]; then + echo "[WARNING] $filename already symlinked" + return + fi + + if [ -e "$destination" ]; then + echo "[ERROR] $destination exists but it's not a symlink. Please fix that manually" + exit 1 + fi + + ln -s "$filename" "$destination" + echo "[OK] $filename -> $destination" +} + +deployManifest() { + for row in $(cat $SCRIPT_DIR/$1); do + if [[ "$row" =~ ^#.* ]]; then + continue + fi + + filename=$(echo $row | cut -d \| -f 1) + operation=$(echo $row | cut -d \| -f 2) + destination=$(echo $row | cut -d \| -f 3) + + case $operation in + symlink) + symlinkFile $filename $destination + ;; + + *) + echo "[WARNING] Unknown operation $operation. Skipping..." + ;; + esac + done +} + +echo "--- Common configs ---" +deployManifest MANIFEST +echo "--- Linux configs ---" +deployManifest MANIFEST.linux