Skip to content

Commit 92cdf37

Browse files
committed
feat: update shell
1 parent f07ac60 commit 92cdf37

File tree

9 files changed

+76
-138
lines changed

9 files changed

+76
-138
lines changed

shell/README.md

Lines changed: 16 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,25 @@
1-
# Shell
2-
3-
Bash scripts around this project, to be used instead of as a VS Code extension. **This area is not complete and is still experimental.**
4-
5-
Note: All the scripts in this directory are named with dashes and not underscores, to match the Git hook filenames convention.
6-
7-
8-
## Samples
9-
10-
Archive of shell scripts for reference. These are used in the early development of the project but are not actively used.
11-
12-
- [count-files.sh](count-files.sh)
13-
- [sample.sh](sample.sh)
14-
- [simple-hook.sh](simple-hook.sh)
15-
16-
17-
## Autofill scripts
18-
19-
These are shell scripts to integrate with the JS scripts in this project, as an alternative to using, VS Code so I can use it any terminal and in other IDEs with their terminals. And if I stop using VS Code completely I can keep using the core at least in a terminal.
20-
21-
- [autofill-hook.sh](autofill-hook.sh)
22-
- [autofill.sh](autofill.sh)
23-
24-
They are not complete but work as a POC for using the core logic outside project outside of VS Code as Git hook.
25-
26-
### Dev notes
271

28-
Remember to **compile** the TS to JS before running this script to get the latest changes. Or use a pre-compiled script.
29-
30-
#### Purpose
31-
32-
This script should be used as an **alternative** to using VS Code itself to handle your commit messages, as VS Code does not support a hook properly when going through the UI box (it actually **ignores** any message you type in and uses its own generated message from the hook).
33-
34-
But, if you don't use it as an actual hook, there is an alternative flow that doesn't mess with VS Code. You can use the other script and set up a Git alias (which can be used across projects without setting a hook even).
35-
36-
Sample output:
37-
38-
```console
39-
$ ./shell/autofill.sh
40-
chore: update settings.json
41-
$ ./shell/autofill.sh
42-
update 11 files
43-
```
44-
45-
Use it with Git. This uses the tool to generate a message and pass it as the Git commit message, but forcing edit mode so you can override it.
46-
47-
```sh
48-
$ git commit --edit -m "$(shell/autofill.sh)"
49-
```
50-
51-
Move the script to a `bin` executables directory so you can run it from anywhere.
52-
53-
```sh
54-
$ cp autofill.sh /usr/local/bin
55-
```
56-
57-
TODO:
58-
59-
- [ ] Where to put the Node script so it can reference it.
60-
- [ ] Windows support
61-
- [ ] How to automated the install process for upgrades. Maybe the JS + shell script as NPM package or at least on GitHub with cURL install.
62-
- [ ] Figure out how to switch between staged and not, with `--cached`. Like passing a param to the shell script and having two aliases. Or to have it as pass of the shell script to fallback to all if anything is staged. Or just control with filenames e.g. `git c .` or `git c package*` - oh wait, the shell script doesn't look at what is passed to `git commit`, only what is staged or not.
2+
# Shell
633

64-
#### Alias
4+
See [acm-hook.sh](acm-hook.sh).
655

66-
Set this up in git config aliases as `c` or something. If this was in a _bin_ directory, or used with an absolute path to the script.
6+
A CLI script that bypasses using VS Code or an extension.
7+
It will get output from Git, send it to Node CLI entry-point tool and print
8+
it. This can be used as part of Git commit message hook flow (pre-commit hook).
679

68-
```toml
69-
[alias]
70-
c = '! git commit --edit -m "$(autofill.sh)"'
71-
```
7210

73-
Then instead of `git commit`, you can do:
11+
## Setup
7412

75-
```sh
76-
$ git c
13+
If you want to use the hook:
7714

78-
$ git c foo.txt
79-
```
15+
1. Follow instructions to install the TS command globally as per [src/cli/README.md](/src/cli/README.md)
16+
1. Install the pre-commit hook.
17+
```sh
18+
$ cp shell/acm-hook.sh YOUR_PROJECT/.hooks/pre-commit
19+
$ chmod +x YOUR_PROJECT/.hooks/pre-commit
20+
```
8021

81-
#### TODO
22+
## Debugging
8223

83-
- [ ] For now this points to the output directory so it limited in real world use. This is a stepping
84-
stone. But ideally the JS files can be copied outside of this project to a central location (maybe
85-
with a `bin` entry point). And the SH script can be added to an individual project in `.git/hooks` dir as `prepare-commit-msg`.
86-
- [ ] When using this as a hook, consider reading from the **existing** commit message file in the case
87-
of template, so it that can be passed on.
88-
- [ ] Add a flag for staged to get `--cached` flag.
24+
Optionally add a `-p` debug flag to print without writing to a file. This
25+
makes it easy to debug the script outside a Git commit hook flow.

shell/TODO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- [ ] For now this points to the output directory so it limited in real world use. This is a stepping
2+
stone. But ideally the JS files can be copied outside of this project to a central location (maybe
3+
with a `bin` entry point). And the SH script can be added to an individual project in `.git/hooks` dir as `prepare-commit-msg`.
4+
- [ ] When using this as a hook, consider reading from the **existing** commit message file in the case
5+
of template, so it that can be passed on.
6+
- [ ] Add a flag for staged to get `--cached` flag.
7+
- [ ] How to automated the install process for upgrades. Maybe the JS + shell script as NPM package or at least on GitHub with cURL install.
8+
- [ ] Figure out how to switch between staged and not, with `--cached`. Like passing a param to the shell script and having two aliases. Or to have it as pass of the shell script to fallback to all if anything is staged. Or just control with filenames e.g. `git c .` or `git c package*` - oh wait, the shell script doesn't look at what is passed to `git commit`, only what is staged or not.
9+
- Fix bug where message is on modified and staged but only staged is commit with gacm
10+
11+
If the flag is omitted, then the standard `git status` logic is followed:
12+
look for staged changes and use them, otherwise use unstaged changes.
13+
there's a problem - commit does not take cached flag - but it will use implied staged or not. so do not pass through.
14+
BUT could look at advanced mode of pass through names of files to commit IF they are handled by status and commit, but using manual git add is good enough probably. esp for untracked files which need add anyway.

shell/acm-hook.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# CLI test for autofill hook.
3+
#
4+
# See shell/README.md doc.
5+
set -e
6+
7+
GENERATE_CMD='auto_commit_msg_generate'
8+
9+
if ! command -v "$GENERATE_CMD" &> /dev/null; then
10+
echo "Error: $GENERATE_CMD could not be found"
11+
exit 1
12+
fi
13+
14+
COMMIT_MSG_FILE=$1
15+
COMMIT_SOURCE=$2
16+
17+
echo 'Input values'
18+
echo "COMMIT_MSG_FILE = $COMMIT_MSG_FILE"
19+
# Either 'message' or 'template'
20+
echo "COMMIT_SOURCE = $COMMIT_SOURCE"
21+
22+
# TODO: Test this - this conditional is untested.
23+
if [ "$COMMIT_SOURCE" = 'template']; then
24+
echo "Current commit message"
25+
<"$COMMIT_MSG_FILE"
26+
fi
27+
28+
CHANGES=$(git diff-index --name-status HEAD)
29+
MESSAGE=$($GENERATE_CMD "$CHANGES")
30+
31+
if [ "$1" = '-p' ]; then
32+
echo "$MESSAGE"
33+
else
34+
echo "$MESSAGE" >$COMMIT_MSG_FILE
35+
fi

shell/archive/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Shell
2+
3+
Bash scripts around this project, to be used instead of as a VS Code extension.
4+
5+
## Samples
6+
7+
Archive of shell scripts for reference. These are used in the early development of the project but are not actively used.
8+
9+
- [count-files.sh](count-files.sh)
10+
- [sample.sh](sample.sh)
11+
- [simple-hook.sh](simple-hook.sh)
File renamed without changes.

shell/autofill-hook.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

shell/autofill.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)