Skip to content

Commit afdca4d

Browse files
committed
feat: ✨ revamp aliases
1 parent 16bc137 commit afdca4d

File tree

5 files changed

+141
-42
lines changed

5 files changed

+141
-42
lines changed

src/common-utils/_zz_context.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ if [ -z "$target" ]; then
4545

4646
if [ -w /usr/local/share ]; then
4747
target=/usr/local/share/$feature
48-
elif [ -w /tmp ]; then
49-
target=/tmp/$feature
48+
#elif [ -w /tmp ]; then
49+
# target=/tmp/$feature
5050
else
5151
echo "${Red}No writeable directory found${End}" >&2
5252
exit 1

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "common-utils",
33
"name": "Common Utils",
44
"description": "Common utils for tomgrv/devcontainer-features",
5-
"version": "3.14.0",
5+
"version": "3.15.0",
66
"dependsOn": {
77
"ghcr.io/devcontainers/features/common-utils": {}
88
},

src/gitutils/alias.json

Lines changed: 132 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,134 @@
11
{
2-
"amend": "git diff-index --cached --quiet HEAD || git commit --amend -C HEAD",
3-
"beta": "git release-beta",
4-
"cleanup": "git stash save --include-untracked --keep-index; git clean --force -d -x -e \".env*\"; git stash apply --index; git stash drop",
5-
"co": "git commit -m \"$1\"",
6-
"conflict": "git diff --name-only --diff-filter=U",
7-
"continue": "git checkout -- . && git rebase --continue",
8-
"crush": "git stash save --keep-index --include-untracked && git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})",
9-
"editLast": "git commit --amend --edit",
10-
"fixable": "git log --oneline $(git rev-parse --abbrev-ref --symbolic-full-name @{u})..HEAD",
11-
"fixAuthor": "git config \"${1---global}\" user.name \"$(git log -2 --pretty=format:'%an' | tail -1)\" && git config \"${1---global}\" user.email \"$(git log -2 --pretty=format:'%ae' | tail -1)\"",
12-
"fixConfig": "git config --global --get-regexp '^alias.' | grep '/tmp' | cut -d ' ' -f1 | while read -r alias; do git config --global --unset \"$alias\"; done",
13-
"fixMode": "git diff -p -R --no-color | grep -E \"^(diff|(old|new) mode)\" --color=never | git apply --allow-empty --no-index",
14-
"forceable": "git log --oneline $(echo $(git rev-parse --abbrev-ref --symbolic-full-name @{u};git log --merges --first-parent -1 --pretty=%h)| tail -1)..HEAD $*",
15-
"go": "git commit -m \"$1\" --all",
16-
"hfix": "git release-hotfix",
17-
"histo": "git log --oneline $(git log --merges --first-parent -1 --pretty=%h) $*",
18-
"ignore": "grep -qxF \"$1\" .gitignore || echo \"$1\" >>.gitignore && git rm --cached \"$1\" 2>/dev/null",
19-
"initFrom": "git clone --origin template --branch master --depth 1 -- $1 $2 && cd $2 && git branch -m master template && git checkout -b master && git checkout -b develop",
20-
"isChanged": "git diff --name-only HEAD@{1} HEAD | grep -q \"^$1\" && exit 0 || exit 1",
21-
"isDirty": "git diff --name-only | grep -q \"^$1\" && exit 0 || exit 1",
22-
"isFixup": "git log -1 --pretty=%s | grep -q fixup! && exit 0 || exit 1",
23-
"isRebase": "git rev-parse --git-dir | grep -q rebase-merge || git rev-parse --git-dir | grep -q rebase-apply",
24-
"pf": "git push --force-with-lease",
25-
"prod": "git release-prod",
26-
"rAbort": "git rebase --abort",
27-
"rCont": "git rebase --continue",
28-
"renameTag": "set -e;git tag $2 $1; git tag -d $1;git push origin :refs/tags/$1;git push --tags",
29-
"stack": "git commit --amend --no-edit --no-verify -C HEAD",
30-
"sync": "git fetch --progress --prune --recurse-submodules=no origin && git stash save --keep-index --include-untracked && git merge --ff-only @{u} && git stash pop --index || git stash drop",
31-
"undo": "git reset --soft HEAD^ --"
2+
"abort": {
3+
"cmd": "git rebase --abort",
4+
"help": "Abort an ongoing rebase."
5+
},
6+
"alias": {
7+
"cmd": "git config --system alias.$1 \"!sh -c 'set -e; git hint \"$2\" \\$1; $3' -- \\$@\"",
8+
"help": "Create a new alias for a git command. Usage: git alias <alias> <help> <command>"
9+
},
10+
"amend": {
11+
"cmd": "git diff-index --cached --quiet HEAD || git commit --amend --reset-author -C HEAD",
12+
"help": "Amend the last commit if there are staged changes."
13+
},
14+
"cleanup": {
15+
"cmd": "git stash save --include-untracked --keep-index; git clean --force -d -x -e \".env*\"; git stash apply --index; git stash drop",
16+
"help": "Stash all changes, clean untracked files except .env*, and restore stash."
17+
},
18+
"co": {
19+
"cmd": "git commit -m \"$1\"",
20+
"help": "Commit with a message."
21+
},
22+
"conflict": {
23+
"cmd": "git diff --name-only --diff-filter=U",
24+
"help": "List files with merge conflicts."
25+
},
26+
"continue": {
27+
"cmd": "git checkout -- . && git rebase --continue",
28+
"help": "Restore all files and continue a rebase."
29+
},
30+
"editLast": {
31+
"cmd": "git commit --amend --edit",
32+
"help": "Edit the last commit message and content."
33+
},
34+
"fixable": {
35+
"cmd": "git log --oneline $(git rev-parse --abbrev-ref --symbolic-full-name @{u})..HEAD",
36+
"help": "Show commits ahead of upstream."
37+
},
38+
"fixAuthor": {
39+
"cmd": "git config \"${1---global}\" user.name \"$(git log -2 --pretty=format:'%an' | tail -1)\" && git config \"${1---global}\" user.email \"$(git log -2 --pretty=format:'%ae' | tail -1)\"",
40+
"help": "Set user.name and user.email to previous commit's author."
41+
},
42+
"fixConfig": {
43+
"cmd": "rm -f ~/.gitconfig",
44+
"help": "Remove the global git config file."
45+
},
46+
"fixMode": {
47+
"cmd": "git diff -p -R --no-color | grep -E \"^(diff|(old|new) mode)\" --color=never | git apply --allow-empty --no-index",
48+
"help": "Restore file mode changes from diff."
49+
},
50+
"forceable": {
51+
"cmd": "git log --oneline $(echo $(git rev-parse --abbrev-ref --symbolic-full-name @{u};git log --merges --first-parent -1 --pretty=%h)| tail -1)..HEAD $*",
52+
"help": "Show commits since last merge or upstream."
53+
},
54+
"fwb": {
55+
"cmd": "git release-beta",
56+
"help": "Run release-beta command."
57+
},
58+
"fwf": {
59+
"cmd": "git flow start feature $1",
60+
"help": "Start a new git flow feature branch."
61+
},
62+
"fwh": {
63+
"cmd": "git release-hotfix",
64+
"help": "Run release-hotfix command."
65+
},
66+
"fwp": {
67+
"cmd": "git release-prod",
68+
"help": "Run release-prod command."
69+
},
70+
"fwt": {
71+
"cmd": "git tag -a $1 -m \"$1\" && git push origin $1",
72+
"help": "Create and push an annotated tag."
73+
},
74+
"go": {
75+
"cmd": "git commit -m \"$1\" --all",
76+
"help": "Commit all changes with a message."
77+
},
78+
"hint": {
79+
"cmd": "if \"$2\" = \"-h\"; then echo \"Usage: $2\"; git config --get-regexp \"^alias\\.\" | awk \\'{printf \"%-20s\",$1 }\\'",
80+
"help": "Display help hint for aliases. Usage: git hint <help message> [<args>]"
81+
},
82+
"histo": {
83+
"cmd": "git log --oneline $(git log --merges --first-parent -1 --pretty=%h) $*",
84+
"help": "Show log since last merge."
85+
},
86+
"ignore": {
87+
"cmd": "grep -qxF \"$1\" .gitignore || echo \"$1\" >>.gitignore && git rm --cached \"$1\" 2>/dev/null",
88+
"help": "Add file to .gitignore and untrack it."
89+
},
90+
"initFrom": {
91+
"cmd": "git clone --origin template --branch master --depth 1 -- $1 $2 && cd $2 && git branch -m master template && git checkout -b master && git checkout -b develop",
92+
"help": "Clone as template, create master and develop branches."
93+
},
94+
"isChanged": {
95+
"cmd": "git diff --name-only HEAD@{1} HEAD | grep -q \"^$1\" && exit 0 || exit 1",
96+
"help": "Check if file changed between last two HEADs."
97+
},
98+
"isDirty": {
99+
"cmd": "git diff --name-only | grep -q \"^$1\" && exit 0 || exit 1",
100+
"help": "Check if file has unstaged changes."
101+
},
102+
"isFixup": {
103+
"cmd": "git log -1 --pretty=%s | grep -q fixup! && exit 0 || exit 1",
104+
"help": "Check if last commit is a fixup commit."
105+
},
106+
"isRebase": {
107+
"cmd": "git rev-parse --git-dir | grep -q rebase-merge || git rev-parse --git-dir | grep -q rebase-apply",
108+
"help": "Check if a rebase is in progress."
109+
},
110+
"pf": {
111+
"cmd": "git push --force-with-lease",
112+
"help": "Push with force-with-lease."
113+
},
114+
"refresh": {
115+
"cmd": "git stash save --keep-index --include-untracked && git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})",
116+
"help": "Stash, reset to upstream, and restore stash."
117+
},
118+
"renameTag": {
119+
"cmd": "set -e;git tag $2 $1; git tag -d $1;git push origin :refs/tags/$1;git push --tags",
120+
"help": "Rename a tag locally and remotely."
121+
},
122+
"stack": {
123+
"cmd": "git diff-index --cached --quiet HEAD || git commit --amend --reset-author --no-edit --no-verify -C HEAD",
124+
"help": "Amend last commit without editing message."
125+
},
126+
"sync": {
127+
"cmd": "git fetch --progress --prune --recurse-submodules=no origin && git stash save --keep-index --include-untracked && git merge --ff-only @{u} && git stash pop --index || git stash drop",
128+
"help": "Fetch, stash, fast-forward merge, and restore stash."
129+
},
130+
"undo": {
131+
"cmd": "git reset --soft HEAD^ --",
132+
"help": "Undo last commit, keep changes staged."
133+
}
32134
}

src/gitutils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "gitutils",
33
"name": "Git Aliases",
44
"description": "A feature to add useful Git aliases to your shell.",
5-
"version": "5.12.3",
5+
"version": "5.13.2",
66
"dependsOn": {
77
"ghcr.io/devcontainers/features/node:1": "lts",
88
"ghcr.io/tomgrv/devcontainer-features/common-utils:3": {

src/gitutils/install-config.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ eval $(
44
zz_context "$@"
55
)
66

7-
# Set Context
8-
GIT_CONFIG_SCOPE="--system"
9-
107
# Check if jq is installed
118
if ! command -v jq >/dev/null 2>&1; then
129
zz_log e "jq is not installed. Please install jq to proceed."
@@ -20,22 +17,22 @@ zz_log i "Installing git configuration in {Purple $GIT_CONFIG_SCOPE} scope..."
2017
if [ -f "$source/config.json" ]; then
2118
zz_log i "Configuring git with {U $source/config.json}..."
2219
jq -r 'paths(scalars) as $p | [($p|join(".")), (getpath($p)|tostring)] | join(" ")' $source/config.json | while read key value; do
23-
git config $GIT_CONFIG_SCOPE $key "$value" && zz_log - "Created config $key => $value"
20+
git config --system $key "$value" && zz_log - "Created config $key => $value"
2421
done
2522
fi
2623

2724
### For each entry in alias.json file next to this file, create corresponding git alias from key and value
2825
if [ -f "$source/alias.json" ]; then
2926
zz_log i "Configuring aliases with {U $source/alias.json}..."
30-
jq -r 'keys[]' $source/alias.json | dos2unix | while read key; do
31-
value=$(jq -r ".$key" $source/alias.json)
32-
git config $GIT_CONFIG_SCOPE alias.$key "!sh -c '$value' -- \"\$@\"" && zz_log - "Created alias {B $key} => {B $value}"
27+
jq -r 'keys[]' $source/alias.json | while read key; do
28+
value=$(jq -r ".$key.cmd" $source/alias.json)
29+
git config --system alias.$key "!sh -c '$value' -- \"\$@\"" && zz_log - "Created alias {B $key} => {B $value}"
3330
done
3431
fi
3532

3633
### For each script starting with _, create corresponding git alias without _ from script name
3734
zz_log i "Configuring scripts with {U $feature/_xx.sh}..."
3835
for script in $target/_*.sh; do
3936
alias=$(basename $script | sed -e 's/^_//g' -e 's/.sh$//g')
40-
git config $GIT_CONFIG_SCOPE alias.$alias "!sh -c '$(readlink -f $script) \$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9' -- \"\$@\"" && zz_log - "Created alias {B $alias} => {B $(readlink -f $script)}"
37+
git config --system alias.$alias "!sh -c '$(readlink -f $script) \$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9' -- \"\$@\"" && zz_log - "Created alias {B $alias} => {B $(readlink -f $script)}"
4138
done

0 commit comments

Comments
 (0)