Skip to content

Commit

Permalink
Added functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mudiarto committed Nov 16, 2024
1 parent d5b0ee1 commit c3cc8b5
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.
36 changes: 36 additions & 0 deletions dot_zsh/functions/chezmoi.sh
Original file line number Diff line number Diff line change
@@ -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"

20 changes: 20 additions & 0 deletions dot_zsh/functions/one_password.sh
Original file line number Diff line number Diff line change
@@ -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"`
}
20 changes: 20 additions & 0 deletions dot_zsh/functions/tmux.sh
Original file line number Diff line number Diff line change
@@ -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'


8 changes: 8 additions & 0 deletions dot_zsh/functions/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Description: Utility functions

# make directory and cd into it
function mcd () {
mkdir -v -p $1
cd $1
}

36 changes: 34 additions & 2 deletions dot_zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -115,15 +146,15 @@ fi
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias cm="chezmoi"


# extra settings

# add xonsh path - in case I want to use xonsh
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)"
Expand All @@ -132,3 +163,4 @@ eval "$(atuin init zsh)"
# from: https://stackoverflow.com/a/58188295
bindkey -v


0 comments on commit c3cc8b5

Please sign in to comment.