97 lines
3.1 KiB
Plaintext
97 lines
3.1 KiB
Plaintext
if [[ -z "$(which-command chezmoi)" && -x "$HOME/bin/chezmoi" ]]; then
|
|
function chezmoi() {
|
|
"$HOME/bin/chezmoi" "${@}"
|
|
}
|
|
fi
|
|
if [[ -n "$(which-command chezmoi)" ]]; then
|
|
export CHEZMOIROOT="$(chezmoi source-path)"
|
|
export CZ="$CHEZMOIROOT"
|
|
export CZ_X="$(readlink -f $CHEZMOIROOT/../_externals)"
|
|
|
|
alias czcd="cd $CZ"
|
|
alias czxcd="cd $CZ_X"
|
|
alias czx-edit="edit $CZ_X/.chezmoiexternal.*"
|
|
|
|
function cz() { chezmoi "${@}"; }
|
|
function czx() {
|
|
chezmoi --source $CZ_X --config $HOME/.config/chezmoi.externals/config.toml "${@}"
|
|
}
|
|
|
|
alias czs="cz status --exclude scripts "
|
|
|
|
CZG_ROOT="$(cz git -- rev-parse --show-toplevel)"
|
|
alias czg="git --work-tree=$CZG_ROOT --git-dir=$CZG_ROOT/.git "
|
|
unset CZG_ROOT
|
|
|
|
alias czgs="czg status "
|
|
alias czgca="czg add --all && czg commit "
|
|
alias cza="cz apply && exec $SHELL"
|
|
alias czu="cz upgrade && cz update && exec $SHELL "
|
|
alias czxu="cz upgrade && cz update && czx apply && exec $SHELL "
|
|
alias czxa="czx apply && exec $SHELL "
|
|
|
|
function cz-refresh() {
|
|
local _tmp
|
|
_tmp=$(chezmoi status --exclude scripts)
|
|
if [[ -n "$_tmp" ]]; then
|
|
echo "Adding modified files..."
|
|
cz re-add
|
|
else
|
|
echo "No modified files found."
|
|
fi
|
|
|
|
_tmp=$(chezmoi unmanaged | grep "^${SFP/\./\\.}\.shrc\.d/" | while read u; do
|
|
printf "'$HOME/$u' "
|
|
done)
|
|
[[ -n "$(echo $_tmp | xargs)" ]] \
|
|
&& echo "Adding new files..." \
|
|
&& eval "chezmoi add --prompt $_tmp"
|
|
}
|
|
|
|
alias cz-commit="cz git -- commit -a "
|
|
|
|
function cz-get-data() {
|
|
chezmoi data --format json | jq -r ".${@:-${SFP#*.}}"
|
|
}
|
|
function cz-import-data() {
|
|
# Use this with eval: eval $(cz-import-data)
|
|
local tmp_SFP=${SFP^^}
|
|
tmp_SFP=${tmp_SFP#*.}
|
|
local UPPERCASE='|ascii_upcase'
|
|
local PREFIX="CZ_${tmp_SFP}_DATA_"
|
|
[[ "$1" == "promptString" ]] && unset UPPERCASE PREFIX
|
|
local RESULTS=$(cz-get-data | jq -r "to_entries[] | \"$PREFIX\(.key${UPPERCASE})=\\\"\(.value)\\\"\"")
|
|
if [[ "$1" == "promptString" ]] ; then
|
|
printf "$RESULTS" | tr '\n' ',' | sed 's/"//g; s/^\(.*\),$/"\1/g;'
|
|
#printf "$RESULTS" | tr '\n' ',' | sed 's/="/=/g; s/^\(.*\),$/"\1/g; s/,/,"/g;'
|
|
else
|
|
echo "$RESULTS"
|
|
fi
|
|
}
|
|
|
|
function cz-remove-missing() {
|
|
pushd ~ > /dev/null
|
|
changes=$(cz status | sed -n 's/^DA[ \t]\+//p')
|
|
for c in $changes; do
|
|
cz rm $c
|
|
done
|
|
popd > /dev/null
|
|
}
|
|
|
|
function cz-set-ssh-github() {
|
|
cz git -- remote set-url origin "$( \
|
|
cz git -- remote get-url origin \
|
|
| sed 's|https://github.com/|git@github.com:|' \
|
|
)"
|
|
cz git -- remote get-url origin
|
|
}
|
|
|
|
function cz-set-https-github() {
|
|
cz git -- remote set-url origin "$( \
|
|
cz git -- remote get-url origin \
|
|
| sed 's|git@github.com:|https://github.com/|' \
|
|
)"
|
|
cz git -- remote get-url origin
|
|
}
|
|
fi
|