diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc index dd923ab..09a5290 100755 --- a/zsh/.config/zsh/.zshrc +++ b/zsh/.config/zsh/.zshrc @@ -3,73 +3,6 @@ # Default umask value umask 0027 -# ========== Functions ========== -# Fuzzy-find a file and open it in less -_run_fless() { - fless && zle reset-prompt -} - -zle -N _run_fless -bindkey -M viins '^n' _run_fless - -# Fuzzy find a file and then edit it - -_run_fedit() { - fedit && zle reset-prompt -} - -_run_etcedit() { - fedit --etc && zle reset-prompt -} - -zle -N _run_fedit -bindkey -M viins '^o' _run_fedit - -zle -N _run_etcedit -bindkey -M viins '^e' _run_etcedit - -# Fuzzy cd from anywhere -# Dependencies -# * fzf -# * mlocate - -cf() { - [[ -z "${*}" ]] && return 1 - [[ ! -x $(which fzf) ]] && return 1 - - #dir="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --select-1 --exit-0)" - #dir="$(locate -0i -- "${@}" | fzf --read0 --select-1 --exit-0)" - dir="$(fd --ignore-file "${XDG_CONFIG_HOME}/fd_ignore" --print0 --type d -- "${@}" | fzf --read0 --select-1 --exit-0)" - - [[ -z "${dir}" ]] && return 1 - - if [[ -f "${dir}" ]]; then - cd "${dir%/*}" - else - cd "${dir}" - fi -} - -autoload -Uz cf - -rgenv() { - if [[ -n $1 ]]; then - env | rg --ignore-case $1 - else - return 0 - fi -} - -# Update a docker container using docker compose -# Note: must be in the container directory -dockerupdate() { - docker compose down - until docker compose pull; do - docker compose pull - done - docker compose up -d -} - # Detect OS to autoload uncommon config files if [[ "$(uname)" =~ "Darwin" ]]; then for dotfile in "$XDG_CONFIG_HOME"/zsh-macos/*zsh*(.); do diff --git a/zsh/.config/zsh/cf.zsh b/zsh/.config/zsh/cf.zsh new file mode 100644 index 0000000..847524f --- /dev/null +++ b/zsh/.config/zsh/cf.zsh @@ -0,0 +1,22 @@ +# Fuzzy cd from anywhere +# Dependencies +# * fzf +# * mlocate +cf() { + [[ -z "${*}" ]] && return 1 + [[ ! -x $(which fzf) ]] && return 1 + + #dir="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --select-1 --exit-0)" + #dir="$(locate -0i -- "${@}" | fzf --read0 --select-1 --exit-0)" + dir="$(fd --ignore-file "${XDG_CONFIG_HOME}/fd_ignore" --print0 --type d -- "${@}" | fzf --read0 --select-1 --exit-0)" + + [[ -z "${dir}" ]] && return 1 + + if [[ -f "${dir}" ]]; then + cd "${dir%/*}" + else + cd "${dir}" + fi +} + +autoload -Uz cf diff --git a/zsh/.config/zsh/dockerupdate.zsh b/zsh/.config/zsh/dockerupdate.zsh new file mode 100644 index 0000000..f5291ff --- /dev/null +++ b/zsh/.config/zsh/dockerupdate.zsh @@ -0,0 +1,20 @@ +# Update a docker container using docker compose +# +# Run this command safely by: +# - Ensuring the docker binary exists +# - The docker-compose.(yml|yaml) file is readable +# - Waiting 5 seconds between docker compose pulls to avoid being rate limited +dockerupdate() { + # If either docker is not installed or docker-compose file is missing, do not run + if [[ ! -x "$(which docker)" ]] && ([[ ! -r docker-compose.yml ]] || [[ ! -r docker-compose.yaml ]]); then + return + else + docker compose down + until docker compose pull; do + docker compose pull + # Do not run this command too often + sleep 5 + done + docker compose up -d + fi +} diff --git a/zsh/.config/zsh/file-scripts.zsh b/zsh/.config/zsh/file-scripts.zsh new file mode 100644 index 0000000..2770664 --- /dev/null +++ b/zsh/.config/zsh/file-scripts.zsh @@ -0,0 +1,24 @@ +# Shell integrations for file-scripts +# Fuzzy-find a file and open it in less +_run_fless() { + fless && zle reset-prompt +} + +zle -N _run_fless +bindkey -M viins '^n' _run_fless + +# Fuzzy find a file and then edit it + +_run_fedit() { + fedit && zle reset-prompt +} + +_run_etcedit() { + fedit --etc && zle reset-prompt +} + +zle -N _run_fedit +bindkey -M viins '^o' _run_fedit + +zle -N _run_etcedit +bindkey -M viins '^e' _run_etcedit diff --git a/zsh/.config/zsh/rgenv.zsh b/zsh/.config/zsh/rgenv.zsh new file mode 100644 index 0000000..9a72cdd --- /dev/null +++ b/zsh/.config/zsh/rgenv.zsh @@ -0,0 +1,8 @@ +# Case-insensitive filter for environment variables +rgenv() { + if [[ -n $1 ]]; then + env | rg --ignore-case $1 + else + return 0 + fi +}