From c3cc8b51830b6beb5b92b52150b7f064704c754c Mon Sep 17 00:00:00 2001 From: Kusno Mudiarto Date: Sat, 16 Nov 2024 04:12:40 -0800 Subject: [PATCH] Added functions --- dot_zsh/functions/chezmoi.sh | 36 +++++++++++++++++++++++++++++++ dot_zsh/functions/one_password.sh | 20 +++++++++++++++++ dot_zsh/functions/tmux.sh | 20 +++++++++++++++++ dot_zsh/functions/utils.sh | 8 +++++++ dot_zshrc | 36 +++++++++++++++++++++++++++++-- 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 dot_zsh/functions/chezmoi.sh create mode 100644 dot_zsh/functions/one_password.sh create mode 100644 dot_zsh/functions/tmux.sh create mode 100644 dot_zsh/functions/utils.sh diff --git a/dot_zsh/functions/chezmoi.sh b/dot_zsh/functions/chezmoi.sh new file mode 100644 index 0000000..9707ff1 --- /dev/null +++ b/dot_zsh/functions/chezmoi.sh @@ -0,0 +1,36 @@ +# chezmoi aliases & utils + +# based from: https://github.com/mass8326/zsh-chezmoi + +# Ensure chezmoi is available +[[ $+commands[chezmoi] ]] || return 0 + +# Completion +source <(chezmoi completion zsh) + +# Status +alias cm="chezmoi" +alias cmd="chezmoi diff" +alias cmcd="chezmoi cd" +alias cmst="chezmoi status" +alias cmdoc="chezmoi doctor" + +# Editing source +alias cma="chezmoi add" +alias cmr="chezmoi re-add" +alias cme="chezmoi edit" +alias cmea="chezmoi edit --apply" +alias chcd="chezmoi cd" + +# Updating target +alias cmap="chezmoi apply" +alias cmup="chezmoi update" +alias cmug="chezmoi upgrade" + +# git +alias cmg="chezmoi git" + + +# helpers +alias zshrc="chezmoi edit --apply ~/.zshrc && omz reload" + diff --git a/dot_zsh/functions/one_password.sh b/dot_zsh/functions/one_password.sh new file mode 100644 index 0000000..bc742b8 --- /dev/null +++ b/dot_zsh/functions/one_password.sh @@ -0,0 +1,20 @@ +# one password function + +function op.signin() { + eval $(op signin) +} + +function op.ensure_signedin() { + op whoami >/dev/null 2>&1 + retVal=$? + if [ $retVal -ne 0 ]; then + op.signin + fi +} + +function ssh-add.load_keys() { + op.ensure_signedin + echo "loading specified keys from 1Password" + # load all specified ssh-keys + ssh-add - <<< `op read "op://Keys/20221016_mudiarto_at_gmail_com/id_ed25519"` +} \ No newline at end of file diff --git a/dot_zsh/functions/tmux.sh b/dot_zsh/functions/tmux.sh new file mode 100644 index 0000000..d49fa6c --- /dev/null +++ b/dot_zsh/functions/tmux.sh @@ -0,0 +1,20 @@ +################################################################################# +# tmux +################################################################################ + +alias tm='tmux' + +# new session-name +alias tm-new='tmux new -A -s' +alias tmn='tmux new -A -s' + +# join session-name +# note - this will detach others connected to the current session +alias tm-join='tmux attach -d -t' +alias tmj='tmux attach -d -t' + +# ls +alias tm-ls='tmux ls' +alias tml='tmux ls' + + diff --git a/dot_zsh/functions/utils.sh b/dot_zsh/functions/utils.sh new file mode 100644 index 0000000..1a03e22 --- /dev/null +++ b/dot_zsh/functions/utils.sh @@ -0,0 +1,8 @@ +# Description: Utility functions + +# make directory and cd into it +function mcd () { + mkdir -v -p $1 + cd $1 +} + diff --git a/dot_zshrc b/dot_zshrc index 0bb17ed..5058e80 100644 --- a/dot_zshrc +++ b/dot_zshrc @@ -4,6 +4,10 @@ # Path to your Oh My Zsh installation. export ZSH="$HOME/.oh-my-zsh" +# dotzsh location +export DOTZSH_HOME=$HOME/.zsh + + # Set name of the theme to load --- if set to "random", it will # load a random theme each time Oh My Zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME @@ -104,6 +108,33 @@ fi # kusno personal aliases/settings # + +# add completion support +# see: https://stackoverflow.com/a/67161186 +autoload -U +X compinit && compinit +autoload -U +X bashcompinit && bashcompinit + +# report time for execution > n secs +# see: https://stackoverflow.com/a/46855194 +export REPORTTIME=5 + +# editor +export VISUAL=vim +export EDITOR=$VISUAL +export PAGER="less" +# -e -> exit on EOF +# -F -> quit if one screen +# -R -> raw control chars +# -X -> no term init +export LESS="eFRX" + + +# load custom functions +for function in $DOTZSH_HOME/functions/*.sh; do + source $function +done + + # Set personal aliases, overriding those provided by Oh My Zsh libs, # plugins, and themes. Aliases can be placed here, though Oh My Zsh # users are encouraged to define aliases within a top-level file in @@ -115,7 +146,7 @@ fi # Example aliases # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh" -alias cm="chezmoi" + # extra settings @@ -123,7 +154,7 @@ alias cm="chezmoi" export PATH=/home/kusno/.local/xonsh-env/xbin/:$PATH # fzf - fuzzy finder -[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh +# [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh # atuin - magical shell history eval "$(atuin init zsh)" @@ -132,3 +163,4 @@ eval "$(atuin init zsh)" # from: https://stackoverflow.com/a/58188295 bindkey -v +