diff --git a/.editorconfig b/.editorconfig index c1d757f..3123ac4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,8 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[Makefile] +tab_width = 8 +indent_size = 8 +indent_style = tab diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index defaafb..84cbede 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: sudo apt install zsh -y - name: Run Tests - run: ./test + run: make test release: needs: - test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3466cb..f47b467 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,4 +20,4 @@ jobs: sudo apt install zsh -y - name: Run Tests - run: ./test + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17ec4fc --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +# Makefile for running common project tasks + +# The default target to run when no arguments are given +.PHONY: all +all: help + +# Run the test script +.PHONY: test +test: + ./test + +# Update snapshots by running the update_snapshot.zsh script +.PHONY: update-snapshots +update-snapshots: + ./tests/update_snapshot.zsh + +# Update the README by running the update_readme_help.zsh script +.PHONY: update-readme +update-readme: + ./tools/update_readme_help.zsh + +# Install the pre-commit hook +.PHONY: install-pre-commit +install-pre-commit: + @echo "Installing pre-commit hook..." + @echo "#!/usr/bin/env zsh\nmake test" > .git/hooks/pre-commit + @chmod +x .git/hooks/pre-commit + @echo "Pre-commit hook installed" + +# Clean +.PHONY: clean +clean: + rm -f .git/hooks/pre-commit + +# Display help +.PHONY: help +help: + @echo "Usage:" + @echo " make test # Run the test script" + @echo " make update-snapshots # Run the update_snapshot.zsh script" + @echo " make update-readme # Run the update_readme_help.zsh script" + @echo " make install-pre-commit # Install the pre-commit hook" + @echo " make clean # Clean" + diff --git a/README.md b/README.md index cdef50e..7509240 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,23 @@ git open file .gitignore # open specific file URL You can always use `git open` without arguments to see the list of possible options: + ```sh -git open +Usage: git open [-s] -Usage: git open Commands: - project|repo|open|. Open the project - branch Open the project at given (or current) branch - commit Open the project at given (or current) commit - file Open the project at given file. Can also append ref hash - prs Open the PR list - pr Open a new PR - actions|pipelines|ci Open the CI/CD pipelines + project|repo|repository|open|. Open the project + branch Open the project at given (or current) branch + commit Open the project at given (or current) commit + file Open the project at given file. Can also append ref hash + prs|mrs Open the PR list + pr|mr Open a new PR + actions|pipelines|ci Open the CI/CD pipelines + +Flags: + -s, --silent Silent mode (no output) ``` + ## Installation diff --git a/tests/update_snapshot.zsh b/tests/update_snapshot.zsh index 38cc190..e574233 100755 --- a/tests/update_snapshot.zsh +++ b/tests/update_snapshot.zsh @@ -1,4 +1,6 @@ #!/usr/bin/env zsh snap="${0:A:h}/snapshot.txt" +echo "Updating snapshot $snap" . "${0:A:h}/../git-open.zsh" > $snap +echo "Snapshot updated" diff --git a/tools/update_readme_help.zsh b/tools/update_readme_help.zsh new file mode 100755 index 0000000..c4b3a82 --- /dev/null +++ b/tools/update_readme_help.zsh @@ -0,0 +1,22 @@ +#!/bin/zsh + +file="README.md" +helpfile="${0:A:h}/../tests/snapshot.txt" +tmpfile=$(mktemp) +help="$(cat $helpfile)" + +echo "Updating help in $file" + +# Write content up to and including the tag +sed -n '//q;p' "$file" >> "$tmpfile" +echo "" >> "$tmpfile" + +# Append the content of the $help variable +echo "\`\`\`sh\n$help\n\`\`\`" >> "$tmpfile" + +# Append content from the tag onwards +sed -n '//,$p' "$file" >> "$tmpfile" + +mv "$tmpfile" "$file" + +echo "Help updated"