Skip to content

Commit e6ad636

Browse files
committed
for shell, copy 1 file, update 3 files and create 1 file
1 parent b66e722 commit e6ad636

File tree

5 files changed

+94
-104
lines changed

5 files changed

+94
-104
lines changed

shell/README-old.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Shell
2+
3+
Bash scripts around this project, to be used instead of as a VS Code extension.
4+
5+
<!-- TODO rewrite this content, remove, and move to src/bin -->
6+
7+
## Samples
8+
9+
Archive of shell scripts for reference. These are used in the early development of the project but are not actively used.
10+
11+
- [count-files.sh](count-files.sh)
12+
- [sample.sh](sample.sh)
13+
- [simple-hook.sh](simple-hook.sh)
14+
15+
16+
## acm scripts
17+
18+
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.
19+
20+
- [acm-hook.sh](acm-hook.sh)
21+
- [acm.sh](acm.sh)
22+
23+
They are not complete but work as a POC for using the core logic outside project outside of VS Code as Git hook.
24+
25+
### Dev notes
26+
27+
Remember to **compile** the TS to JS before running this script to get the latest changes. Or use a pre-compiled script.
28+
29+
#### Purpose
30+
31+
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).
32+
33+
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).
34+
35+
Sample output:
36+
37+
```console
38+
$ ./shell/acm.sh
39+
chore: update settings.json
40+
$ ./shell/acm.sh
41+
update 11 files
42+
```
43+
44+
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.
45+
46+
```sh
47+
$ git commit --edit -m "$(shell/acm.sh)"
48+
```
49+
50+
This can be done easier using the bin and alias steps below.
51+
52+
Move the script to a `bin` executables directory so you can run it from anywhere.
53+
54+
```sh
55+
$ cp acm.sh /usr/local/bin
56+
```
57+
58+
#### Alias
59+
60+
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.
61+
62+
```toml
63+
[alias]
64+
c = '! git commit --edit -m "$(acm.sh)"'
65+
```
66+
67+
Then instead of `git commit`, you can do:
68+
69+
```sh
70+
$ git c
71+
72+
$ git c foo.txt
73+
```

shell/README.md

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,11 @@
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-
9-
Approaches
10-
11-
- Make installable via repo with cp or npm link (better with esbuild for support of any module not just amd and system)
12-
- Or with GH URL for repo
13-
- Or with binary which is more effort and not needed for everyone
14-
15-
-->
16-
17-
## Samples
18-
19-
Archive of shell scripts for reference. These are used in the early development of the project but are not actively used.
20-
21-
- [count-files.sh](count-files.sh)
22-
- [sample.sh](sample.sh)
23-
- [simple-hook.sh](simple-hook.sh)
24-
25-
26-
## acm scripts
27-
28-
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.
29-
30-
- [acm-hook.sh](acm-hook.sh)
31-
- [acm.sh](acm.sh)
32-
33-
They are not complete but work as a POC for using the core logic outside project outside of VS Code as Git hook.
34-
35-
### Dev notes
36-
37-
Remember to **compile** the TS to JS before running this script to get the latest changes. Or use a pre-compiled script.
38-
39-
#### Purpose
401

41-
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).
42-
43-
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).
44-
45-
Sample output:
46-
47-
```console
48-
$ ./shell/acm.sh
49-
chore: update settings.json
50-
$ ./shell/acm.sh
51-
update 11 files
52-
```
53-
54-
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.
55-
56-
```sh
57-
$ git commit --edit -m "$(shell/acm.sh)"
58-
```
59-
60-
This can be done easier using the bin and alias steps below.
61-
62-
Move the script to a `bin` executables directory so you can run it from anywhere.
63-
64-
```sh
65-
$ cp acm.sh /usr/local/bin
66-
```
67-
68-
TODO:
69-
70-
- [ ] Where to put the Node script so it can reference it.
71-
- [ ] Windows support
72-
- [ ] How to automated the install process for upgrades. Maybe the JS + shell script as NPM package or at least on GitHub with cURL install.
73-
- [ ] 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.
74-
75-
#### Alias
76-
77-
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.
78-
79-
```toml
80-
[alias]
81-
c = '! git commit --edit -m "$(acm.sh)"'
82-
```
83-
84-
Then instead of `git commit`, you can do:
85-
86-
```sh
87-
$ git c
88-
89-
$ git c foo.txt
90-
```
2+
# Shell
913

92-
#### TODO
4+
If you want to use the hook:
935

94-
- [ ] For now this points to the output directory so it limited in real world use. This is a stepping
95-
stone. But ideally the JS files can be copied outside of this project to a central location (maybe
96-
with a `bin` entry point). And the SH script can be added to an individual project in `.git/hooks` dir as `prepare-commit-msg`.
97-
- [ ] When using this as a hook, consider reading from the **existing** commit message file in the case
98-
of template, so it that can be passed on.
99-
- [ ] Add a flag for staged to get `--cached` flag.
6+
1. Follow instructions to install the TS command globally as per [src/bin/README.md](/src/bin/README.md)
7+
1. Install the pre-commit hook.
8+
```sh
9+
$ cp shell/acm-hook.sh YOUR_PROJECT/.hooks/pre-commit
10+
$ chmod +x YOUR_PROJECT/.hooks/pre-commit
11+
```

shell/TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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.

shell/acm-hook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [ "$COMMIT_SOURCE" = 'template']; then
3535
fi
3636

3737
CHANGES=$(git diff-index --name-status HEAD)
38-
MESSAGE=$(acm "$CHANGES")
38+
MESSAGE=$(auto_commit_msg_generate "$CHANGES")
3939

4040
if [ "$1" = '-p' ]; then
4141
echo "$MESSAGE"

shell/acm.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
#
44
# Produce a commit message from changed files and print to stdout.
55
#
6-
# This works similar to a Git hook, but is intended to be used alone or in a Git
7-
# alias.
8-
#
9-
# See `shell/README.md` doc.
10-
# See `src/git/cli.ts` for details on flags. Note `--cached` can be added
11-
# if you want to use staged changes only.
6+
# The preferred way is to use a TS command in `src/bin` instead, to avoid
7+
# having to put this .sh script in a bin directory when npm link works.
8+
# But this was the original way.`
129
set -e
1310

1411
DIFF_FLAGS='--name-status --find-renames --find-copies --no-color'
1512
CHANGES=$(git diff-index $DIFF_FLAGS HEAD)
1613

17-
MESSAGE=$(acm "$CHANGES")
14+
MESSAGE=$(auto_commit_msg_generate "$CHANGES")
1815
echo "$MESSAGE"

0 commit comments

Comments
 (0)