Skip to content

Commit

Permalink
Add general sparce-edit cmd (replaces readme cmd)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfunx committed May 8, 2018
1 parent 369f6f1 commit 4139c98
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dotfiles
Expand Up @@ -144,12 +144,14 @@ edit_info() {
git --git-dir "$dotfiles_dir" checkout --quiet
}

readme() {
local readme_file="$(mktemp --suffix .md)"
git --git-dir="$dotfiles_dir" 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
rm "$readme_file"
sparse_edit() {
local original_file="${1:-README.md}" sparse_file extension ; shift
extension=$([[ "$original_file" = *.* ]] && echo ".${original_file##*.}" || echo '')
sparse_file="$(mktemp --suffix "$extension")"
git --git-dir="$dotfiles_dir" show :"$original_file" > "$sparse_file"
${EDITOR:-vim} "$sparse_file"
git --git-dir="$dotfiles_dir" update-index --add --cacheinfo 10064,$(git --git-dir="$dotfiles_dir" hash-object -w "$sparse_file"),"$original_file"
rm "$sparse_file"
git --git-dir "$dotfiles_dir" checkout --quiet
}

Expand All @@ -175,8 +177,11 @@ case $dot_cmd in
attributes)
edit_info attributes .gitattributes "$@"
;;
edit)
sparse_edit "$@"
;;
readme)
$dot_cmd
sparse_edit README.md "$@"
;;
*)
git --git-dir="$dotfiles_dir" $dot_cmd "$@"
Expand Down

0 comments on commit 4139c98

Please sign in to comment.