Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper function for git command #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions dotfiles
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ _EOF_
}
# }}}

_git() {
git --git-dir="$dotfiles_dir" "$@"
}

# Init {{{
init_setup() {
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}"
echo "dotfiles_dir=$dotfiles_dir" > "${XDG_CONFIG_HOME:-$HOME/.config}"/dotfiles.conf
sparse_tree > "$dotfiles_dir"/info/sparse-checkout
git --git-dir "$dotfiles_dir" config --local core.bare false
git --git-dir "$dotfiles_dir" config --local core.worktree ~
git --git-dir "$dotfiles_dir" config --local core.sparseCheckout true
git --git-dir "$dotfiles_dir" config --local status.showUntrackedFiles no
_git config --local core.bare false
_git config --local core.worktree ~
_git config --local core.sparseCheckout true
_git config --local status.showUntrackedFiles no
}

init() {
Expand All @@ -145,9 +149,9 @@ clone() {
git clone --bare "$1" "$dotfiles_dir" || error "failed to clone '$1'"
init_setup
# If there is no .gitignore yet, this will just clobber some comments
git --git-dir "$dotfiles_dir" show HEAD:.gitignore > "$dotfiles_dir"/info/exclude 2>/dev/null
git --git-dir "$dotfiles_dir" show HEAD:.gitattributes > "$dotfiles_dir"/info/attributes 2>/dev/null
git --git-dir "$dotfiles_dir" checkout
_git show HEAD:.gitignore > "$dotfiles_dir"/info/exclude 2>/dev/null
_git show HEAD:.gitattributes > "$dotfiles_dir"/info/attributes 2>/dev/null
_git checkout
}
# }}}

Expand All @@ -159,17 +163,17 @@ edit_info() {
else
printf '%s\n' "$@" >> "$infofile"
fi
git --git-dir="$dotfiles_dir" update-index --add --cacheinfo 10064,$(git --git-dir="$dotfiles_dir" hash-object -w "$infofile"),"$dotfile"
git --git-dir "$dotfiles_dir" checkout --quiet
_git update-index --add --cacheinfo 10064,$(_git hash-object -w "$infofile"),"$dotfile"
_git checkout --quiet
}

readme() {
local readme_file="$(mktemp -dt dotfiles.XXXXXX)/README.md"
git --git-dir="$dotfiles_dir" show :README.md > "$readme_file"
_git show :README.md > "$readme_file"
${EDITOR:-vim} "$readme_file"
git --git-dir="$dotfiles_dir" update-index --add --cacheinfo 10064,$(git --git-dir="$dotfiles_dir" hash-object -w "$readme_file"),README.md
_git update-index --add --cacheinfo 10064,$(_git hash-object -w "$readme_file"),README.md
rm -r "${readme_file%README.md}"
git --git-dir "$dotfiles_dir" checkout --quiet
_git checkout --quiet
}

# Main
Expand Down Expand Up @@ -201,5 +205,5 @@ case $dot_cmd in
$dot_cmd
;;
*)
git --git-dir="$dotfiles_dir" $dot_cmd "$@"
_git $dot_cmd "$@"
esac