mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
feat: Moves most configuration
This commit is contained in:
256
env/.config/zsh/.zshrc
vendored
Executable file
256
env/.config/zsh/.zshrc
vendored
Executable file
@@ -0,0 +1,256 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# _
|
||||
# _______| |__ _ __ ___
|
||||
# |_ / __| '_ \| '__/ __|
|
||||
# / /\__ \ | | | | | (__
|
||||
# /___|___/_| |_|_| \___|
|
||||
#
|
||||
#
|
||||
#------------------------------ utilites ------------------------------
|
||||
|
||||
_source_if() { test -r "$1" && source "$1" || return 0 }
|
||||
|
||||
#------------------------------ exports ------------------------------
|
||||
autoload -U up-line-or-beginning-search
|
||||
autoload -U down-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
# Colors
|
||||
autoload -Uz colors && colors
|
||||
|
||||
#------------------------------ pager ------------------------------
|
||||
#eval "$(batman --export-env)"
|
||||
# export LESS_TERMCAP_mb="[35m" # magenta
|
||||
# export LESS_TERMCAP_md="[33m" # yellow
|
||||
# export LESS_TERMCAP_me=""
|
||||
# export LESS_TERMCAP_se=""
|
||||
# export LESS_TERMCAP_so="[34m" # blue
|
||||
# export LESS_TERMCAP_ue=""
|
||||
# export LESS_TERMCAP_so="[4m" # underline
|
||||
# export LESSHISTFILE="-"
|
||||
|
||||
#------------------------------ path ------------------------------
|
||||
|
||||
# Helper function to prepend to the $PATH
|
||||
path_prepend() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
test -d "$arg" || continue
|
||||
PATH=${PATH//:"$arg:"/:}
|
||||
PATH=${PATH/#"$arg:"/}
|
||||
PATH=${PATH/%":$arg"/}
|
||||
export PATH="$arg${PATH:+":$PATH"}"
|
||||
done
|
||||
} && export path_prepend
|
||||
|
||||
# Helper function to prepend to the $FPATH
|
||||
fpath_prepend() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
test -d "$arg" || continue
|
||||
FPATH=${FPATH//:"$arg:"/:}
|
||||
FPATH=${FPATH/#"$arg:"/}
|
||||
FPATH=${FPATH/%":$arg"/}
|
||||
export FPATH="$arg${FPATH:+":$FPATH"}"
|
||||
done
|
||||
} && export fpath_prepend
|
||||
|
||||
# last arg will be first in $PATH
|
||||
path_prepend \
|
||||
"/usr/local/bin" \
|
||||
"$HOME/.local/share/gem/bin" \
|
||||
"$GOROOT/bin" \
|
||||
"$GOPATH/bin" \
|
||||
"$XDG_DATA_HOME/bin" \
|
||||
"$HOME/.local/bin" \
|
||||
"$SCRIPTS" \
|
||||
"$HOME/.local/pnpm" \
|
||||
"$CARGO_HOME/bin" \
|
||||
"$HOME/.local/bin"
|
||||
|
||||
# last arg will be first in $FPATH
|
||||
fpath_prepend \
|
||||
"$ZDOTDIR/completions" \
|
||||
"$HOME/.local/share/zsh/completions" \
|
||||
"$ZDOTDIR/functions"
|
||||
|
||||
autoload -Uz $fpath[1]/*(.:t)
|
||||
|
||||
#------------------------------ history ------------------------------
|
||||
setopt appendhistory # append to history
|
||||
setopt sharehistory # share history across multiple sessions
|
||||
setopt incappendhistory # adds commands as typed, not at shell exit
|
||||
setopt hist_expire_dups_first # expire duplicates first
|
||||
setopt hist_ignore_dups # do not store duplicates
|
||||
setopt hist_find_no_dups # ignore duplicates when searching
|
||||
setopt hist_reduce_blanks # do not store blank lines.
|
||||
setopt histignorespace # do not store commands that start with a space in history
|
||||
|
||||
export HISTSIZE=5000
|
||||
export HISTFILESIZE=5000
|
||||
export SAVEHIST=5000
|
||||
export HISTFILE="$XDG_CONFIG_HOME/zsh/history"
|
||||
|
||||
#set -o vi
|
||||
|
||||
#------------------------------ cdpath ------------------------------
|
||||
setopt autocd
|
||||
|
||||
# NOTE: This may be overriden in local env overrides (typically located in $XDG_DATA_HOME/zsh/env.zsh
|
||||
export CDPATH=".:$REPOS:$REPOS/ansible:$DOTFILES:$LOCAL_REPOS:$BUCKET:$HOME"
|
||||
|
||||
#------------------------------ options ------------------------------
|
||||
# (see `man zshoptions`)
|
||||
setopt chaselinks
|
||||
setopt extended_glob
|
||||
setopt glob_dots
|
||||
setopt glob_star_short
|
||||
setopt clobber
|
||||
setopt interactive_comments
|
||||
setopt aliases
|
||||
setopt auto_pushd # Push the current directory on the stack.
|
||||
setopt pushd_ignore_dups # Ignore duplicates in stack
|
||||
setopt pushd_silent # Do not print stack after pushd or popd.
|
||||
setopt CORRECT # Offers corrections on misspelled commands.
|
||||
|
||||
bindkey -v # Enable vi mode
|
||||
export KEYTIMEOUT=1 # Switch between vim mode quicker.
|
||||
|
||||
# Load Useful Functions
|
||||
_source_if "${ZDOTDIR}/zsh-functions"
|
||||
|
||||
# Plugins
|
||||
zsh_add_plugin "zsh-users/zsh-autosuggestions"
|
||||
zsh_add_plugin "zsh-users/zsh-syntax-highlighting"
|
||||
zsh_add_plugin "Aloxaf/fzf-tab"
|
||||
|
||||
#------------------------------ completions ------------------------------
|
||||
# case insensitive path-completion
|
||||
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
|
||||
|
||||
# partial completion suggestions
|
||||
zstyle ':completion:*' list-suffixes
|
||||
#
zstyle ':completion:*' expand prefix suffix
|
||||
|
||||
zstyle ':completion:*' menu no
|
||||
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
|
||||
|
||||
autoload -Uz compinit; compinit # zstyle(s) should be added before this.
|
||||
zmodload zsh/complist
|
||||
_comp_options+=(globdots) # Include hidden files.
|
||||
|
||||
autoload bashcompinit && bashcompinit
|
||||
[[ -r "$PASSWORD_STORE_DIR/.extensions/completions/extensions.bash.completion" ]] && \
|
||||
source "$PASSWORD_STORE_DIR/.extensions/completions/extensions.bash.completion"
|
||||
|
||||
_source_if "$ZDOTDIR/plugins/fzf-tab/fzf-tab.plugin.zsh"
|
||||
|
||||
#------------------------------ prompt ------------------------------
|
||||
|
||||
# Prompt / managed by brew. (`brew install starship`)
|
||||
autoload -Uz promptinit; promptinit
|
||||
eval "$(starship init zsh)"
|
||||
#prompt pure
|
||||
|
||||
#------------------------------ aliases ------------------------------
|
||||
|
||||
alias bk='cd "${OLDPWD}"' # change to last directory
|
||||
alias cda='cd "$ANSIBLE_LOCAL"' # change into local ansible directory.
|
||||
alias cl='printf "\e[H\e[2J"' # clear the terminal
|
||||
alias clear='printf "\e[H\e[2J"' # clear the terminal
|
||||
alias czets='cd "${ZETDIR}"' # move into zettlekasten notes
|
||||
alias d='docker' # run docker commands quickly
|
||||
alias dc='docker compose' # run docker-compose commands quickly
|
||||
alias dv='dirs -v' # list directory info
|
||||
alias essh='edit-ssh-config' # edit ssh config quickly
|
||||
alias fl='find-latest' # Find the last modified file in a directory.
|
||||
alias g='git' # access git commands quickly
|
||||
alias ga='git add' # add files to git quickly
|
||||
alias gcb='git checkout -b' # checkout a new git branch, creating if needed.
|
||||
alias gco='git checkout' # checkout an already existing git branch
|
||||
alias gcm='git commit -a -m' # commit files to git quickly
|
||||
alias gen='just --justfile "$ANSIBLE_GEN_DIR/justfile"' # generate template files / directories
|
||||
alias gp='git push' # push repo to git
|
||||
alias gs='git status' # git status quickly
|
||||
alias hn='hugo new' # generate a hugo site
|
||||
alias hnc='hugo new content' # generate new hugo site content quickly
|
||||
alias j='just' # run justfile's quickly.
|
||||
alias l='eza --long --git --group --links --icons --all' # better ls command.
|
||||
alias lfs='ls -lahH --color=auto "$ZDOTDIR/functions"' # List functions.
|
||||
alias ls='eza --long --git --group --links --icons --all'
|
||||
alias lt='eza --long --git --group --links --icons --tree'
|
||||
alias pass='gopass'
|
||||
alias p='gopass' # run the pass command quickly.
|
||||
alias pf='pass fzf' # fuzzy find a password quickly and copy selection to clipboard.
|
||||
alias pg='gopass show' # get an attribute of a password file quickly.
|
||||
alias pgc='gopass show --clip' # get an attribute of a password file and copy to the clipboard.
|
||||
alias reload='exec zsh -l' # reload the shell, useful when making changes.
|
||||
alias s='swift' # shorthand to access swift commands
|
||||
alias st='swift test' # swift test
|
||||
alias sb='swift build' # swift build
|
||||
alias t='tmux' # access tmux quickly
|
||||
alias tka='tmux kill-server' # kill tmux server and all sessions.
|
||||
alias ts='$SCRIPTS/tmux-sessionator' # create new tmux session, fuzzy finding common locations.
|
||||
alias tss='$SCRIPTS/tmux-sessionator --choose' # attach to an existing tmux session.
|
||||
alias tls='tmux list-sessions' # list tmux sessions
|
||||
alias tks='tmux kill-session -t' # kill tmux session
|
||||
alias temp='cd $(mktemp -d)' # create a temporary directory and move into it.
|
||||
alias vi='nvim' # set vi to open neovim
|
||||
alias newf='"$SCRIPTS"/newx --function' # generate a new shell function
|
||||
alias nlnv='nvim "$LOCAL_ENV"' # open local environment overrides file in neovime
|
||||
alias nvim='unset VIMINIT && unset MYVIMRC && nvim' # alias nvim to unset vimrc, useful when using both vim & neovim
|
||||
alias nvim-mhoush='NVIM_APPNAME=m-housh && nvim' # set neovim to use my config.
|
||||
alias nvim-kickstart='NVIM_APPNAME=kickstart nvim' # set neovim to use kickstart config.
|
||||
alias nvim-lazy='NVIM_APPNAME=lazy nvim' # set neovim to use lazy config.
|
||||
alias wget="wget --hsts-file=$XDG_DATA_HOME/wget-hsts" # set wget history location.
|
||||
# GPG Yubikey restart relearn when switching keys and stubbed.
|
||||
alias yubikeyrestart='gpg-connect-agent killagent /bye && gpg-connect-agent "scd serialno" "learn --force" /bye && gpg --card-status'
|
||||
alias z='zoxide'
|
||||
|
||||
# NOTE: This needs to stay near the bottom, or it doesn't work properly.
|
||||
# Use fzf in history / search contexts.
|
||||
source <(fzf --zsh)
|
||||
#source <(kubectl completion zsh)
|
||||
|
||||
#------------------------------ local configs ------------------------------
|
||||
|
||||
# TODO: The .zshrc-local is a legacy location and should be removed once my machines are
|
||||
# use the new location in XDG_DATA_HOME.
|
||||
# HACK: These need to stay here, otherwise environment overrides do not work properly
|
||||
# I tried sourcing them in the the `.zshenv` files, but did not work.
|
||||
_source_if "$ZDOTDIR/.zshrc-local"
|
||||
_source_if "$LOCAL_ENV"
|
||||
|
||||
# pnpm
|
||||
export PNPM_HOME="/Users/michael/.local/share/pnpm"
|
||||
case ":$PATH:" in
|
||||
*":$PNPM_HOME:"*) ;;
|
||||
*) export PATH="$PNPM_HOME:$PATH" ;;
|
||||
esac
|
||||
# pnpm end
|
||||
|
||||
# The following lines have been added by Docker Desktop to enable Docker CLI completions.
|
||||
fpath=(/Users/michael/.docker/completions $fpath)
|
||||
autoload -Uz compinit
|
||||
compinit
|
||||
|
||||
#eval "$(ssh-agent -s)" 1>/dev/null
|
||||
|
||||
########################################
|
||||
# Set things up for using gpg-agent
|
||||
|
||||
export GPG_TTY=$(tty)
|
||||
|
||||
function use-gpg-agent-for-ssh {
|
||||
SOCK="$( gpgconf --list-dirs agent-ssh-socket )"
|
||||
if [[ -n "${SOCK:-}" ]]
|
||||
then
|
||||
unset SSH_AGENT_PID
|
||||
export SSH_AUTH_SOCK="$SOCK"
|
||||
fi
|
||||
}
|
||||
use-gpg-agent-for-ssh
|
||||
|
||||
command -v direnv >/dev/null 2>&1 && eval "$(direnv hook zsh)"
|
||||
command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init --cmd cd zsh)"
|
||||
5
env/.config/zsh/functions/brew-update
vendored
Executable file
5
env/.config/zsh/functions/brew-update
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
function brew-update() {
|
||||
brew update && brew upgrade --greedy && brew cleanup
|
||||
}
|
||||
6
env/.config/zsh/functions/cdots
vendored
Executable file
6
env/.config/zsh/functions/cdots
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
function cdots() {
|
||||
"$SCRIPTS/tmux-sessionator" "$DOTFILES"
|
||||
}
|
||||
|
||||
8
env/.config/zsh/functions/chmox
vendored
Executable file
8
env/.config/zsh/functions/chmox
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# makes files executable
|
||||
|
||||
function chmox() {
|
||||
[ ! -f "$1" ] && echo "usage: chmox <file>" && return 1
|
||||
chmod u+x "$1"
|
||||
}
|
||||
7
env/.config/zsh/functions/clean-screenshots
vendored
Executable file
7
env/.config/zsh/functions/clean-screenshots
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function clean-screenshots() {
|
||||
for file in "$SCREENSHOTS"/*; do
|
||||
rm "$file"
|
||||
done
|
||||
}
|
||||
23
env/.config/zsh/functions/desktop
vendored
Executable file
23
env/.config/zsh/functions/desktop
vendored
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function desktop() {
|
||||
declare hide
|
||||
declare show
|
||||
|
||||
zparseopts -D -E -K -- \
|
||||
{h,-hide}=hide \
|
||||
{s,-show}=show
|
||||
|
||||
if [ -n "$hide" ]; then
|
||||
defaults write com.apple.finder CreateDesktop false && killall Finder
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -n "$show" ]; then
|
||||
defaults write com.apple.finder CreateDesktop true && killall Finder
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Please pass in --hide | --show"
|
||||
return 1
|
||||
}
|
||||
16
env/.config/zsh/functions/dmg
vendored
Executable file
16
env/.config/zsh/functions/dmg
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Creates an encrypted disk image from a folder
|
||||
function dmg() {
|
||||
from="$1"
|
||||
to="$2"
|
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
echo "Usage: dmg <fromdir> <todir>"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
|
||||
name="$(isosec).dmg"
|
||||
hdiutil create -encryption AES-256 -srcfolder "$from" "$to/$name"
|
||||
}
|
||||
12
env/.config/zsh/functions/dp
vendored
Executable file
12
env/.config/zsh/functions/dp
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function dp() {
|
||||
[ -z "$1" ] && echo "Must supply temperature" && return 1
|
||||
[ -z "$2" ] && echo "Must supply relative humidity" && return 1
|
||||
|
||||
local temperature=$1
|
||||
local humidity=$2
|
||||
|
||||
/opt/homebrew/bin/psychrometrics dew-point --dry-bulb "$temperature" --relative-humidity "$humidity"
|
||||
|
||||
}
|
||||
5
env/.config/zsh/functions/edit-ssh-config
vendored
Executable file
5
env/.config/zsh/functions/edit-ssh-config
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function edit-ssh-config() {
|
||||
ansible-vault edit "$DOTFILES/ssh/config"
|
||||
}
|
||||
7
env/.config/zsh/functions/find-latest
vendored
Executable file
7
env/.config/zsh/functions/find-latest
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Find the last modified file in a directory.
|
||||
function find-latest() {
|
||||
local dir=$1
|
||||
echo "$(find $dir -maxdepth 1 -mindepth 1 -type f | sort -nr | head -1)"
|
||||
}
|
||||
8
env/.config/zsh/functions/gl
vendored
Executable file
8
env/.config/zsh/functions/gl
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Prettier git log
|
||||
function gl() {
|
||||
git log --graph \
|
||||
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
|
||||
--abbrev-commit
|
||||
}
|
||||
11
env/.config/zsh/functions/gma
vendored
Executable file
11
env/.config/zsh/functions/gma
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Add all and commit to git.
|
||||
|
||||
function gma() {
|
||||
[ -z "$1" ] \
|
||||
&& echo "usage: gma <commit-message>" \
|
||||
&& return 1
|
||||
|
||||
git add . && git commit -m "$1"
|
||||
}
|
||||
5
env/.config/zsh/functions/gpgreset
vendored
Executable file
5
env/.config/zsh/functions/gpgreset
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function gpgreset() {
|
||||
gpgconf --kill all && gpgconf --launch all
|
||||
}
|
||||
12
env/.config/zsh/functions/mkcd
vendored
Executable file
12
env/.config/zsh/functions/mkcd
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Creates a directory then `cd`'s into the directory
|
||||
|
||||
function mkcd() {
|
||||
dir=$1
|
||||
if [ -z "$dir" ]; then
|
||||
echo "usage: mkcd <dir>" && return 1
|
||||
fi
|
||||
mkdir "$dir"
|
||||
cd "$dir"
|
||||
}
|
||||
25
env/.config/zsh/functions/n
vendored
Executable file
25
env/.config/zsh/functions/n
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Open's neovim.
|
||||
#
|
||||
# If the argument passed in is a directory or not supplied, then
|
||||
# open neovim with telescope find files opened. Otherwise open the
|
||||
# file that is supplied.
|
||||
#
|
||||
|
||||
function n() {
|
||||
# if [ -z "$1" ]; then
|
||||
# local gitdir=$(git rev-parse --show-toplevel 2> /dev/null)
|
||||
#
|
||||
# [ -n "$gitdir" ] \
|
||||
# && nvim -c ":Telescope git_files" \
|
||||
# && return 0
|
||||
#
|
||||
# [ -d "$1" ] \
|
||||
# && nvim -c ":Telescope find_files" \
|
||||
# && return 0
|
||||
# fi
|
||||
|
||||
nvim "$@"
|
||||
}
|
||||
|
||||
13
env/.config/zsh/functions/new-proposal
vendored
Executable file
13
env/.config/zsh/functions/new-proposal
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/zsh
|
||||
|
||||
prefix=$(date '+%y.%m.%d')
|
||||
name=$(gum input --placeholder="Enter customer name...")
|
||||
|
||||
if [ -z "$name" ]; then
|
||||
echo "Name should not be blank." && exit 1
|
||||
fi
|
||||
|
||||
cleanedName="${name%% *}${name##* }"
|
||||
directory="$PROPOSALS/$prefix.$cleanedName"
|
||||
mkdir "$directory"
|
||||
echo "$directory"
|
||||
7
env/.config/zsh/functions/shortdate
vendored
Executable file
7
env/.config/zsh/functions/shortdate
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Formats the date as '23.10.12'.
|
||||
|
||||
function shortdate() {
|
||||
echo "$(date '+%Y.%m.%d' | cut -c3-)"
|
||||
}
|
||||
17
env/.config/zsh/functions/tns
vendored
Executable file
17
env/.config/zsh/functions/tns
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Create a tmux session.
|
||||
#
|
||||
# This accepts a path argument that is used to create the tmux session
|
||||
# in, using it's basename for the session name.
|
||||
#
|
||||
# If an argument is not supplied, then we will create a tmux session in
|
||||
# the current working directory.
|
||||
|
||||
function tns() {
|
||||
local directory=$1
|
||||
if [ -n "$directory" ]; then
|
||||
directory=${PWD}
|
||||
fi
|
||||
tmux-sessionator --directory "$directory"
|
||||
}
|
||||
6
env/.config/zsh/functions/update-dots
vendored
Executable file
6
env/.config/zsh/functions/update-dots
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function update-dots() {
|
||||
find "$ANSIBLE_MACOS_PLAYBOOK_DIR" -type f -maxdepth 1 -mindepth 1 -name justfile \
|
||||
| xargs -I {} just --justfile {} run-playbook --tags dotfiles "$@"
|
||||
}
|
||||
19
env/.config/zsh/functions/vic
vendored
Executable file
19
env/.config/zsh/functions/vic
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/zsh
|
||||
|
||||
function vic() {
|
||||
# opens a shell command in $EDITOR
|
||||
cmd="$(command -v $1)"
|
||||
|
||||
[ -f "$cmd" ] \
|
||||
&& "$EDITOR" "$cmd" \
|
||||
&& return 0
|
||||
|
||||
# if command was not found try the function directory.
|
||||
cmd="$ZFUNCDIR/$1"
|
||||
[ -f "$cmd" ] \
|
||||
&& "$EDITOR" "$cmd" \
|
||||
&& return 0
|
||||
|
||||
echo "Command not found: $1"
|
||||
return 1
|
||||
}
|
||||
32
env/.config/zsh/zsh-functions
vendored
Executable file
32
env/.config/zsh/zsh-functions
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/zsh
|
||||
# Function to source files if they exist
|
||||
function zsh_add_file() {
|
||||
[ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1"
|
||||
}
|
||||
|
||||
function zsh_add_plugin() {
|
||||
PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2)
|
||||
if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
|
||||
# For plugins
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh"
|
||||
else
|
||||
git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
|
||||
fi
|
||||
}
|
||||
|
||||
function zsh_add_completion() {
|
||||
PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2)
|
||||
if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
|
||||
# For completions
|
||||
completion_file_path=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*)
|
||||
fpath+="$(dirname "${completion_file_path}")"
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh"
|
||||
else
|
||||
git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
|
||||
fpath+=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*)
|
||||
[ -f $ZDOTDIR/.zccompdump ] && $ZDOTDIR/.zccompdump
|
||||
fi
|
||||
completion_file="$(basename "${completion_file_path}")"
|
||||
if [ "$2" = true ] && compinit "${completion_file:1}"
|
||||
}
|
||||
Reference in New Issue
Block a user