Skip to content

Commit 2ada3a8

Browse files
authored
Merge pull request #11 from nschlimm/feature/v2.1.5
Feature/v2.1.5
2 parents 8400f00 + f6c412d commit 2ada3a8

File tree

9 files changed

+126
-24
lines changed

9 files changed

+126
-24
lines changed

EasyKey.bash/.ezk-bash-config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
mavenhome=~/.m2
33
workspace=~/workspace
44
easykey=~/workspace/EasyKey.shellmenu
5-
kihon=~/kihon
5+
kihon=~/kihon
6+
sublime=/Users/d6t6/Library/Application Support/Sublime Text/Packages/User

EasyKey.bash/bashstuff.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ source "$script_dir/../shellmenu.sh"
1010
findText(){
1111
echo "Text pattern:"
1212
read textPattern
13+
[ "$textPattern" = "" ] && waitonexit && return
1314
echo "File pattern:"
1415
read filePattern
16+
[ "$filePattern" = "" ] && waitonexit && return
1517
find . -name "$filePattern" -exec grep -Hn "$textPattern" {} + | awk -F ":" '{printf "%-40s %s\n", $1, $2}'
1618
}
1719

1820
findFiles(){
1921
echo "File pattern:"
2022
read filePattern
23+
[ "$filePattern" = "" ] && waitonexit && return
2124
find . -name "$filePattern"
2225
}
2326

2427
findTextAll() {
2528
echo "Text pattern:"
2629
read textPattern
30+
[ "$textPattern" = "" ] && waitonexit && return
2731
find . -type f -exec grep -Hn "$textPattern" {} + | awk -F ":" '{printf "%-40s %-4s %s\n", $1, $2, $3}'
2832
}
2933

@@ -34,6 +38,16 @@ whichSoftware() {
3438
which -a $software
3539
}
3640

41+
filesDo() {
42+
echo "File pattern:"
43+
read filePattern
44+
[ "$filePattern" = "" ] && waitonexit && return
45+
echo "Bash execution one liner (file ref with '\$1'):"
46+
read cbash
47+
[ "$cbash" = "" ] && waitonexit && return
48+
find . -name "$filePattern" -type f -exec sh -c "$cbash" _ {} \;
49+
}
50+
3751
menuInit "EasyKey.bash"
3852
submenuHead "Usefull "
3953
menuItem f "Find files by pattern" findFiles
@@ -43,4 +57,5 @@ menuInit "EasyKey.bash"
4357
menuItem m "Largest files" "find . -type f -exec du -h {} + | sort -rh | head -n 10"
4458
menuItem n "Size of current directory" "du -sh ."
4559
menuItem w "Where is my software installed?" whichSoftware
60+
menuItem e "Find files and do something" filesDo
4661
startMenu "pwd"

EasyKey.git/ezk-git-atln.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function mergeRebase () {
2626
}
2727

2828
cherryPick() {
29-
echo "Last 15 commits"
30-
git log --all --oneline
29+
git log --all --graph --decorate --oneline --format='%C(bold blue)%h%Creset %s %C(bold green)(%cd)%Creset %an' --date=format:'%Y-%m-%d %H:%M'
3130
echo "Enter commit you want to pick:"
3231
read cname
3332
[ "${cname}" = "" ] && waitonexit && return

EasyKey.git/ezk-git-atuc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ checkoutWay() {
5959
git log --all --oneline
6060
echo "Select a commit to checkout:"
6161
read cname
62+
[ "$cname" = "" ] && waitonexit && return
6263
executeCommand "git checkout $cname -- ."
6364
}
6465

EasyKey.git/ezk-git-diff.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ diffStatus() {
101101
git fetch --all
102102
menuInit "Working with diffs"
103103
submenuHead "Different diff options:"
104-
menuItem a "actual branch vs. origin/actual branch. -> local repository vs. remote repository" headHead
105-
menuItem b "actual working dir vs. actual branch last commit -> work dir vs. local repository" dirHead
106-
menuItem c "actual working dir vs. other commits -> work dir vs. local repository" treeCommit
107-
menuItem d "commit vs. commit -> local repository vs. local repository" commitCommit
108-
menuItem e "branch vs. branch -> repository vs. repository (local/remote)" branchBranch
104+
menuItem a "actual branch vs. origin/actual branch" headHead
105+
menuItem b "actual working dir vs. actual branch last commit" dirHead
106+
menuItem c "actual working dir vs. other commits" treeCommit
107+
menuItem d "commit vs. commit" commitCommit
108+
menuItem e "branch vs. branch" branchBranch
109109
submenuHead "Specific diffs:"
110110
menuItem k "Diff since date" diffDate
111111
submenuHead "Other usefull stuff here:"

EasyKey.git/ezk-git-functions.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ function analyzeWorkingDir (){
1919
function pushActual() {
2020
executeCommand "git fetch --all"
2121
importantLog "Checking your head state"
22+
23+
# Check if the current branch has an upstream (remote)
24+
if [ -z "$(git rev-parse --abbrev-ref --symbolic-full-name ${current_branch}@{upstream} 2>/dev/null)" ]; then
25+
echo "The current branch '"$actual"' doesn't have an upstream branch."
26+
echo
27+
echo -n "Do you want to create and attach remot branch (y/n)?" && wait_for_keypress && echo
28+
[ "$REPLY" != "y" ] && waitonexit && return
29+
setUpstream
30+
fi
31+
2232
if git status | grep -q "HEAD detached"; then
2333
redLog "... you seem to be on a detached head state ... can't push ..."
2434
else
@@ -28,6 +38,7 @@ function pushActual() {
2838
commitChanges
2939
pushChanges
3040
fi
41+
waitonexit
3142
}
3243

3344
function pushChanges () {
@@ -65,12 +76,6 @@ function mergeChanges () {
6576
# Get the name of the current branch
6677
current_branch=$(git rev-parse --abbrev-ref HEAD)
6778

68-
# Check if the current branch has an upstream (remote)
69-
if [ -z "$(git rev-parse --abbrev-ref --symbolic-full-name ${current_branch}@{upstream} 2>/dev/null)" ]; then
70-
echo "The current branch '$current_branch' doesn't have an upstream branch."
71-
exit 1
72-
fi
73-
7479
# Get the number of commits ahead of the remote branch
7580
ahead_count=$(git rev-list --count ${current_branch}@{upstream}..${current_branch})
7681
behind_count=$(git rev-list --count ${current_branch}..${current_branch}@{upstream})
@@ -416,4 +421,14 @@ ammendCommit() {
416421
importantLog "Rebase successful"
417422
executeCommand "git push --force origin $actual"
418423
fi
424+
}
425+
426+
prettyLog() {
427+
git log --all --graph --decorate --oneline --format='%C(auto)%ad %h %d %C(bold blue)%an%Creset %s %C(bold red)%D' --date=format:'%Y-%m-%d %H:%M'
428+
}
429+
430+
allBranches() {
431+
git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
432+
executeCommand "git fetch --all"
433+
executeCommand "git pull --all"
419434
}

EasyKey.git/ezk-git-giob.sh

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,57 @@ contCommit() {
2121
echo "Enter commit to display:"
2222
read cname
2323
[ "${cname}" = "" ] && waitonexit && return
24-
git cat-file -p $cname
24+
executeCommand "git cat-file -p $cname"
25+
}
26+
27+
showAllGitObjects() {
28+
# Iterate over each hash
29+
while read -r hash filename; do
30+
# Get the type of object for the hash
31+
obj_type=$(git cat-file -t "$hash")
32+
33+
if [ "$obj_type" = "commit" ]; then
34+
commit_date=$(git cat-file -p $hash | awk '/^author / {print $5}' | xargs date -r)
35+
else
36+
commit_date=""
37+
fi
38+
39+
# Output the hash and its corresponding object type
40+
echo "$hash: $obj_type $filename $commit_date"
41+
done < <({
42+
git rev-list --objects --all
43+
git rev-list --objects -g --no-walk --all
44+
git rev-list --objects --no-walk \
45+
$(git fsck --unreachable |
46+
grep '^unreachable commit' |
47+
cut -d' ' -f3)
48+
} | sort | uniq | sort -k2)
49+
}
50+
51+
currentObjects() {
52+
branch=$(git rev-parse --abbrev-ref HEAD)
53+
importantLog "branch: $branch"
54+
# Step 2: Get the commit object from the branch
55+
commit=$(git rev-parse "$branch")
56+
echo "Enter custom commit to explore or press enter to take branch head!"
57+
read ccommit
58+
[ "$ccommit" != "" ] && commit=$ccommit;
59+
importantLog "commit: $commit"
60+
# Step 3: Get the tree object from the commit object
61+
tree=$(git cat-file -p "$commit" | awk '/^tree/ {print $2}')
62+
importantLog "tree: $tree"
63+
# Step 4: Get all tree and blob objects from the tree object
64+
blueLog "blobs in tree:"
65+
git ls-tree -r "$tree"
66+
blueLog "trees in tree:"
67+
git ls-tree -d "$tree"
68+
}
69+
70+
contObject() {
71+
echo "Enter hash:"
72+
read chash
73+
[ "$chash" = "" ] && waitonexit && return
74+
executeCommand "git cat-file -p $chash"
2575
}
2676

2777
setActual
@@ -32,7 +82,12 @@ menuItem b "Current HEAD pointer" "git symbolic-ref HEAD"
3282
menuItem c "Inspect current tree object" "git cat-file -p ${actual}^{tree}"
3383
menuItem d "Inspect current commit object" "git cat-file -p ${actual}^{commit}"
3484
menuItem e "Show contents of commit object" contCommit
35-
menuItem e "All branches" allBranches
36-
menuItem f "All tags" allTags
85+
menuItem f "All branches" allBranches
86+
menuItem g "All tags" allTags
87+
menuItem h "The actuial list of blobs" "git ls-tree -r HEAD"
88+
menuItem i "The actuial list of trees" "git ls-tree HEAD | grep tree"
89+
menuItem j "All GIT objects" showAllGitObjects
90+
menuItem k "Current objects HEAD>BRANCH>COMMIT>OBJECTS" currentObjects
91+
menuItem l "Show contents of object" contObject
3792
startMenu "setActual"
3893
noterminate

EasyKey.git/git.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ menuInit "EasyKey.git"
1616
menuItemClm e "Set upstream to current" setUpstream f "Administer remotes" adminRemotes
1717
submenuHead "Working on local branches "
1818
menuItemClm r "Show branch history" showBranchHisto g "Show reflog" showRepoHisto
19-
menuItemClm l "Show all commits log" "git log --all --graph --decorate --oneline" p "Show all branches (incl. remote)" showAllBranches
19+
menuItemClm l "Show all commits log" prettyLog p "Show all branches (incl. remote)" showAllBranches
2020
menuItemClm v "Checkout remote branch" coRemoteBranch n "Delete local/remote branch" deleteBranch
2121
menuItemClm k "New local/remote branch checkout" newLocalBranch c "Change commit messages" ammendCommit
22-
menuItem o "Merge source to target branch" mergeSourceToTarget
22+
menuItemClm o "Merge source to target branch" mergeSourceToTarget z "Get all remote branches" allBranches
2323
submenuHead "Other usefull actions "
2424
menuItemClm s "Working with diffs" workingDiffs w "Working with commits" atlassiansView
2525
menuItemClm y "Setting up repositories" settingUp 5 "Git extras" gitExtras

shellmenu.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#################################
66

77
# Release
8-
release=2.1.4
8+
release=2.1.5
99

1010
# Colors
1111
clrBlack=0
@@ -16,6 +16,7 @@ clrBlue=4
1616
clrPurple=5
1717
clrCyan=6
1818
clrWhite=7
19+
clrGray=237
1920

2021
# Globals (SUBJECT TO CUSTOMIZATION)
2122
waitstatus=true # whether to wait for key press after menu command finished
@@ -429,15 +430,29 @@ callKeyFunktion () {
429430
IFS="$delimiter" read -r key description action submenu menu column <<< "$i"
430431
if [ "$1" = "$key" ]
431432
then
432-
clear && importantLog "$action"
433+
clear && actionBanner "$description"
434+
importantLog "$action"
433435
eval "$action"
436+
finishBanner "$description"
434437
return 1
435438
fi
436439
done
437440
return 5
438441
IFS=$OLD_IFS
439442
}
440443

444+
actionBanner() {
445+
local bannerline="$(r_pad " Command Execution" "75" " ")"
446+
coloredLog "$bannerline" $menuHeadingFGClr $menuHeadingBGClr && echo
447+
local actionline="$(r_pad " $1" "75" " ")"
448+
coloredLog "$actionline" $clrWhite $clrGray && echo
449+
}
450+
451+
finishBanner() {
452+
local bannerline="$(r_pad " Command Execution finished" "75" " ")"
453+
coloredLog "$bannerline" $clrWhite $clrGray && echo
454+
}
455+
441456
#################################################
442457
# Generates the menu from the menudatamap.
443458
# Globals:
@@ -591,9 +606,10 @@ printSubmenuHeading(){
591606
# Padded line to stdout
592607
#################################################
593608
r_pad() {
594-
local text=$1
595-
local length=${#text}
596-
local width=${2:-$length}
609+
local text="$1"
610+
local length="${#text}"
611+
local width="${2:-$length}"
612+
local symbol="${3:- }"
597613
local paddedcount=$(( width - length ))
598614
local printout="$text$(printf "%-${paddedcount}s" "" | tr " " "$symbol")"
599615
printf "%s" "$printout"

0 commit comments

Comments
 (0)