Skip to content

Commit

Permalink
Merge pull request #11 from nschlimm/feature/v2.1.5
Browse files Browse the repository at this point in the history
Feature/v2.1.5
  • Loading branch information
nschlimm authored Mar 28, 2024
2 parents 8400f00 + f6c412d commit 2ada3a8
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 24 deletions.
3 changes: 2 additions & 1 deletion EasyKey.bash/.ezk-bash-config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
mavenhome=~/.m2
workspace=~/workspace
easykey=~/workspace/EasyKey.shellmenu
kihon=~/kihon
kihon=~/kihon
sublime=/Users/d6t6/Library/Application Support/Sublime Text/Packages/User
15 changes: 15 additions & 0 deletions EasyKey.bash/bashstuff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ source "$script_dir/../shellmenu.sh"
findText(){
echo "Text pattern:"
read textPattern
[ "$textPattern" = "" ] && waitonexit && return
echo "File pattern:"
read filePattern
[ "$filePattern" = "" ] && waitonexit && return
find . -name "$filePattern" -exec grep -Hn "$textPattern" {} + | awk -F ":" '{printf "%-40s %s\n", $1, $2}'
}

findFiles(){
echo "File pattern:"
read filePattern
[ "$filePattern" = "" ] && waitonexit && return
find . -name "$filePattern"
}

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

Expand All @@ -34,6 +38,16 @@ whichSoftware() {
which -a $software
}

filesDo() {
echo "File pattern:"
read filePattern
[ "$filePattern" = "" ] && waitonexit && return
echo "Bash execution one liner (file ref with '\$1'):"
read cbash
[ "$cbash" = "" ] && waitonexit && return
find . -name "$filePattern" -type f -exec sh -c "$cbash" _ {} \;
}

menuInit "EasyKey.bash"
submenuHead "Usefull "
menuItem f "Find files by pattern" findFiles
Expand All @@ -43,4 +57,5 @@ menuInit "EasyKey.bash"
menuItem m "Largest files" "find . -type f -exec du -h {} + | sort -rh | head -n 10"
menuItem n "Size of current directory" "du -sh ."
menuItem w "Where is my software installed?" whichSoftware
menuItem e "Find files and do something" filesDo
startMenu "pwd"
3 changes: 1 addition & 2 deletions EasyKey.git/ezk-git-atln.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function mergeRebase () {
}

cherryPick() {
echo "Last 15 commits"
git log --all --oneline
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'
echo "Enter commit you want to pick:"
read cname
[ "${cname}" = "" ] && waitonexit && return
Expand Down
1 change: 1 addition & 0 deletions EasyKey.git/ezk-git-atuc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ checkoutWay() {
git log --all --oneline
echo "Select a commit to checkout:"
read cname
[ "$cname" = "" ] && waitonexit && return
executeCommand "git checkout $cname -- ."
}

Expand Down
10 changes: 5 additions & 5 deletions EasyKey.git/ezk-git-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ diffStatus() {
git fetch --all
menuInit "Working with diffs"
submenuHead "Different diff options:"
menuItem a "actual branch vs. origin/actual branch. -> local repository vs. remote repository" headHead
menuItem b "actual working dir vs. actual branch last commit -> work dir vs. local repository" dirHead
menuItem c "actual working dir vs. other commits -> work dir vs. local repository" treeCommit
menuItem d "commit vs. commit -> local repository vs. local repository" commitCommit
menuItem e "branch vs. branch -> repository vs. repository (local/remote)" branchBranch
menuItem a "actual branch vs. origin/actual branch" headHead
menuItem b "actual working dir vs. actual branch last commit" dirHead
menuItem c "actual working dir vs. other commits" treeCommit
menuItem d "commit vs. commit" commitCommit
menuItem e "branch vs. branch" branchBranch
submenuHead "Specific diffs:"
menuItem k "Diff since date" diffDate
submenuHead "Other usefull stuff here:"
Expand Down
27 changes: 21 additions & 6 deletions EasyKey.git/ezk-git-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ function analyzeWorkingDir (){
function pushActual() {
executeCommand "git fetch --all"
importantLog "Checking your head state"

# Check if the current branch has an upstream (remote)
if [ -z "$(git rev-parse --abbrev-ref --symbolic-full-name ${current_branch}@{upstream} 2>/dev/null)" ]; then
echo "The current branch '"$actual"' doesn't have an upstream branch."
echo
echo -n "Do you want to create and attach remot branch (y/n)?" && wait_for_keypress && echo
[ "$REPLY" != "y" ] && waitonexit && return
setUpstream
fi

if git status | grep -q "HEAD detached"; then
redLog "... you seem to be on a detached head state ... can't push ..."
else
Expand All @@ -28,6 +38,7 @@ function pushActual() {
commitChanges
pushChanges
fi
waitonexit
}

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

# Check if the current branch has an upstream (remote)
if [ -z "$(git rev-parse --abbrev-ref --symbolic-full-name ${current_branch}@{upstream} 2>/dev/null)" ]; then
echo "The current branch '$current_branch' doesn't have an upstream branch."
exit 1
fi

# Get the number of commits ahead of the remote branch
ahead_count=$(git rev-list --count ${current_branch}@{upstream}..${current_branch})
behind_count=$(git rev-list --count ${current_branch}..${current_branch}@{upstream})
Expand Down Expand Up @@ -416,4 +421,14 @@ ammendCommit() {
importantLog "Rebase successful"
executeCommand "git push --force origin $actual"
fi
}

prettyLog() {
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'
}

allBranches() {
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
executeCommand "git fetch --all"
executeCommand "git pull --all"
}
61 changes: 58 additions & 3 deletions EasyKey.git/ezk-git-giob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,57 @@ contCommit() {
echo "Enter commit to display:"
read cname
[ "${cname}" = "" ] && waitonexit && return
git cat-file -p $cname
executeCommand "git cat-file -p $cname"
}

showAllGitObjects() {
# Iterate over each hash
while read -r hash filename; do
# Get the type of object for the hash
obj_type=$(git cat-file -t "$hash")

if [ "$obj_type" = "commit" ]; then
commit_date=$(git cat-file -p $hash | awk '/^author / {print $5}' | xargs date -r)
else
commit_date=""
fi

# Output the hash and its corresponding object type
echo "$hash: $obj_type $filename $commit_date"
done < <({
git rev-list --objects --all
git rev-list --objects -g --no-walk --all
git rev-list --objects --no-walk \
$(git fsck --unreachable |
grep '^unreachable commit' |
cut -d' ' -f3)
} | sort | uniq | sort -k2)
}

currentObjects() {
branch=$(git rev-parse --abbrev-ref HEAD)
importantLog "branch: $branch"
# Step 2: Get the commit object from the branch
commit=$(git rev-parse "$branch")
echo "Enter custom commit to explore or press enter to take branch head!"
read ccommit
[ "$ccommit" != "" ] && commit=$ccommit;
importantLog "commit: $commit"
# Step 3: Get the tree object from the commit object
tree=$(git cat-file -p "$commit" | awk '/^tree/ {print $2}')
importantLog "tree: $tree"
# Step 4: Get all tree and blob objects from the tree object
blueLog "blobs in tree:"
git ls-tree -r "$tree"
blueLog "trees in tree:"
git ls-tree -d "$tree"
}

contObject() {
echo "Enter hash:"
read chash
[ "$chash" = "" ] && waitonexit && return
executeCommand "git cat-file -p $chash"
}

setActual
Expand All @@ -32,7 +82,12 @@ menuItem b "Current HEAD pointer" "git symbolic-ref HEAD"
menuItem c "Inspect current tree object" "git cat-file -p ${actual}^{tree}"
menuItem d "Inspect current commit object" "git cat-file -p ${actual}^{commit}"
menuItem e "Show contents of commit object" contCommit
menuItem e "All branches" allBranches
menuItem f "All tags" allTags
menuItem f "All branches" allBranches
menuItem g "All tags" allTags
menuItem h "The actuial list of blobs" "git ls-tree -r HEAD"
menuItem i "The actuial list of trees" "git ls-tree HEAD | grep tree"
menuItem j "All GIT objects" showAllGitObjects
menuItem k "Current objects HEAD>BRANCH>COMMIT>OBJECTS" currentObjects
menuItem l "Show contents of object" contObject
startMenu "setActual"
noterminate
4 changes: 2 additions & 2 deletions EasyKey.git/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ menuInit "EasyKey.git"
menuItemClm e "Set upstream to current" setUpstream f "Administer remotes" adminRemotes
submenuHead "Working on local branches "
menuItemClm r "Show branch history" showBranchHisto g "Show reflog" showRepoHisto
menuItemClm l "Show all commits log" "git log --all --graph --decorate --oneline" p "Show all branches (incl. remote)" showAllBranches
menuItemClm l "Show all commits log" prettyLog p "Show all branches (incl. remote)" showAllBranches
menuItemClm v "Checkout remote branch" coRemoteBranch n "Delete local/remote branch" deleteBranch
menuItemClm k "New local/remote branch checkout" newLocalBranch c "Change commit messages" ammendCommit
menuItem o "Merge source to target branch" mergeSourceToTarget
menuItemClm o "Merge source to target branch" mergeSourceToTarget z "Get all remote branches" allBranches
submenuHead "Other usefull actions "
menuItemClm s "Working with diffs" workingDiffs w "Working with commits" atlassiansView
menuItemClm y "Setting up repositories" settingUp 5 "Git extras" gitExtras
Expand Down
26 changes: 21 additions & 5 deletions shellmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#################################

# Release
release=2.1.4
release=2.1.5

# Colors
clrBlack=0
Expand All @@ -16,6 +16,7 @@ clrBlue=4
clrPurple=5
clrCyan=6
clrWhite=7
clrGray=237

# Globals (SUBJECT TO CUSTOMIZATION)
waitstatus=true # whether to wait for key press after menu command finished
Expand Down Expand Up @@ -429,15 +430,29 @@ callKeyFunktion () {
IFS="$delimiter" read -r key description action submenu menu column <<< "$i"
if [ "$1" = "$key" ]
then
clear && importantLog "$action"
clear && actionBanner "$description"
importantLog "$action"
eval "$action"
finishBanner "$description"
return 1
fi
done
return 5
IFS=$OLD_IFS
}

actionBanner() {
local bannerline="$(r_pad " Command Execution" "75" " ")"
coloredLog "$bannerline" $menuHeadingFGClr $menuHeadingBGClr && echo
local actionline="$(r_pad " $1" "75" " ")"
coloredLog "$actionline" $clrWhite $clrGray && echo
}

finishBanner() {
local bannerline="$(r_pad " Command Execution finished" "75" " ")"
coloredLog "$bannerline" $clrWhite $clrGray && echo
}

#################################################
# Generates the menu from the menudatamap.
# Globals:
Expand Down Expand Up @@ -591,9 +606,10 @@ printSubmenuHeading(){
# Padded line to stdout
#################################################
r_pad() {
local text=$1
local length=${#text}
local width=${2:-$length}
local text="$1"
local length="${#text}"
local width="${2:-$length}"
local symbol="${3:- }"
local paddedcount=$(( width - length ))
local printout="$text$(printf "%-${paddedcount}s" "" | tr " " "$symbol")"
printf "%s" "$printout"
Expand Down

0 comments on commit 2ada3a8

Please sign in to comment.