0

Two git functions defined in .gitconfig (using alias)

create-file = "!f() { for name in \"$@\"; do echo $name>$name.txt; done; }; f"

m-commit = "!f() { for name in \"$@\"; do git create-file $name; done; }; f"

git m-commit a b c

This runs ok from the top-level directory of a git repo.

How to make it to run it from subdirectory, (to create test files in this subdirectory, not in the top)

Thanks for any help.

phd
  • 82,685
  • 13
  • 120
  • 165
aniecki
  • 11
  • Why don't you just `alias m-commit="for name in \"$@\"; do echo $name>$name.txt; done;"` in bash? – Geno Chen Feb 06 '19 at 19:23
  • Besides, you'd better provide something about the actual occurrence when you run it in subdirectory. – Geno Chen Feb 06 '19 at 19:26
  • Yeah, there is no reason for either command to be a Git alias; the former doesn't use Git at all and the latter only does because `create-file` is a Git alias. – chepner Feb 06 '19 at 19:41
  • If I update create-file = "!createFile() { for name in \"$@\"; do echo $name>\"${GIT_PREFIX:-.}\"/$name.txt; done; }; createFile" this will work as git create_file a b c - but still not as git m_commit a b c - as files will be still created in the top directory. This excise is educational, to commit many simple files in any sub directories of the repo. – aniecki Feb 06 '19 at 21:02

1 Answers1

1

The name of the top-level directory is output by git rev-parse --show-toplevel.

chepner
  • 497,756
  • 71
  • 530
  • 681