Skip to content

Commit

Permalink
Merge pull request #7 from nschlimm/feature/EasyKey.bash
Browse files Browse the repository at this point in the history
Feature/easy key.bash
  • Loading branch information
nschlimm authored Mar 20, 2024
2 parents 04c84f4 + 9c013d7 commit dbddf0b
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EasyKey.git/.ezk-git-loca-conf
4 changes: 4 additions & 0 deletions EasyKey.bash/.ezk-bash-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[locations]
mavenhome=~/.m2
workspace=~/workspace
easykey=~/workspace/EasyKey.shellmenu
3 changes: 3 additions & 0 deletions EasyKey.bash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# EasyKey.bash utility

Experimental state of menu with usefull bash commands.
21 changes: 21 additions & 0 deletions EasyKey.bash/bashstuff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

####################################
# EasyKey.bash utility main script #
####################################

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$script_dir/../shellmenu.sh"

findText(){
echo "Text pattern:"
read textPattern
echo "File pattern:"
read filePattern
find . -name "$filePattern" -exec grep -H "$textPattern" {} + | awk -F ":" '{printf "%-40s %s\n", $1, $2}'
}

menuInit "EasyKey.bash"
submenuHead "Usefull:"
menuItem f "Find text inside files" findText
startMenu "$(pwd)"
44 changes: 44 additions & 0 deletions EasyKey.bash/ezk-locations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

unset locations

script_dir="$1"
source "${script_dir}/shellmenu.sh"

configfilename=.ezk-bash-config

function toDirAndTerminate () {
vars="$*" # all splitted words back to one var
blueLog "toDir $vars"
eval "cd ${vars// /\\ }" # escape spaces
nowaitonexit
}

# Reads the config into global array "workspaces"
# The config needs to have that section [workspaces]
initConfig "${script_dir}/EasyKey.bash/${configfilename}"

echo "${locations[@]}"

clear
thekeys=($(echo {a..p}) $(echo {r..z}) $(echo {1..9}) $(echo {A..Z}))
declare -x keycounter=1

immediateMode=true

menuInit "Quick Locations"
echo
submenuHead "Registered locations:"
OLD_IFS=$IFS
for (( i = 1; i < (( ${#locations[@]} + 1 )); i++ )); do
IFS="=" read -r locname locdestination <<< "${locations[i]}"
menuItem "${thekeys[keycounter]}" "$locdestination" "toDirAndTerminate ${locdestination}"
((keycounter++))
done
IFS=$OLD_IFS
echo
submenuHead "Shortcuts"
menuItem X "Purge git dir cache" purgDirCache
choice

unset locations
4 changes: 0 additions & 4 deletions EasyKey.git/.ezk-git-loca-conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[workspaces]
myworkspacelocation=~/workspace

[locations]
mavenrepohome=~/.m2
userbin=/usr/local/bin

13 changes: 13 additions & 0 deletions EasyKey.git/ezk-git-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ function atlassiansView() {

function changeProject () {
source $script_dir/../EasyKey.git/ezk-git-loca.sh
noterminate
nowaitonexit
}

Expand Down Expand Up @@ -365,3 +366,15 @@ diffDrillDownAdvanced () {
done
fi
}

repoSize() {
executeCommand "git gc"
executeCommand "git count-objects -vH"
executeCommand "git rev-list --objects --all | grep -f <(git verify-pack -v .git/objects/pack/*.idx| sort -k 3 -n | cut -f 1 -d ' ' | tail -10)"
echo "Enter file pattern to REMOVE in repo history:"
read filePattern
[ "${filename}" = "" ] && waitonexit && return
executeCommand "git filter-repo --path-glob '"${filePattern}"' --invert-paths --force"
executeCommand "git gc"
executeCommand "git count-objects -vH"
}
54 changes: 5 additions & 49 deletions EasyKey.git/ezk-git-loca.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,14 @@ function purgDirCache () {
unset gitlocations
}

initConfig () {
# read config to global arrays
INPUT="$script_dir"/"$configfilename"
[ ! -f "$INPUT" ] && { echo "$INPUT file not found"; exit 99; }
i=0
configlines=$(cat "$INPUT")
while read -r configline; do
if echo "$configline" | grep -q "\[.*\]"; then
configsection=$(echo "$configline" | grep -o "\[.*\]")
configsectioname=${configsection:1:${#configsection}-2}
i=0
continue
fi
if [ -n "$configline" ]; then
eval "${configsectioname[i]}='$configline'"
fi
((i++))
done <<< "$(echo -e "$configlines")"
}

initConfig
# Reads the config into global array "workspaces"
# The config needs to have that section [workspaces]
initConfig "${script_dir}/${configfilename}"

clear
thekeys=($(echo {a..p}) $(echo {r..z}) $(echo {1..9}) $(echo {A..Z}))
declare -x keycounter=0
menuInit "Favorite locations"
submenuHead "Locations:"
if [ -n ${locations+x} ]; then
for j in "${locations[@]}"
do
locationname=$(echo "$j" | cut -f1 -d'=')
locationdir=$(echo "$j" | cut -f2 -d'=')
menuItem "${thekeys[$keycounter]}" "$locationname" "toDirAndTerminate $locationdir"
((keycounter++))
done
fi
echo
submenuHead "Workspaces:"
if [ -n ${workspaces+x} ]; then
for j in "${workspaces[@]}"
do
locationname=$(echo "$j" | cut -f1 -d'=')
locationdir=$(echo "$j" | cut -f2 -d'=')
menuItem "${thekeys[$keycounter]}" "$locationname" "toDir $locationdir"
((keycounter++))
done
fi
menuInit "GIT locations"
echo
uncached=false
priorlocation=$(pwd) # remember actual location
Expand All @@ -88,6 +49,7 @@ fi
eval cd "${priorlocation// /\\ }" # return to previous location
# print out git location cache
submenuHead "GIT repos inside workspaces:"
echo
for (( i = 0; i < ${#gitlocations[@]}; i++ )); do
arrIN=(${gitlocations[$i]})
IFSOLD=$IFS
Expand All @@ -97,14 +59,8 @@ for (( i = 0; i < ${#gitlocations[@]}; i++ )); do
menuItem "${arrIN[0]}" "${arrIN[1]}" "${arrIN[2]} ${arrIN[3]}"
done
if $uncached; then coloredLog "NEW" "1;42"; else coloredLog "CACHED" "1;42"; fi
echo
submenuHead "Shortcuts"
menuItem X "Purge git dir cache" purgDirCache
echo
menuItem q "Quit" quit
echo
coloredLog "$(pwd)" "1;44"

choice

unset locations workspaces
7 changes: 3 additions & 4 deletions EasyKey.git/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ menuItem r "Show branch history" showBranchHisto
echo
submenuHead "Other usefull actions:"
menuItemClm s "Working with diffs" workingDiffs w "Atlassian's view" atlassiansView
menuItem c "Change last commit message" "git commit --amend"
menuItemClm c "Change last commit message" "git commit --amend" x "Descrease repo size" repoSize
echo
submenuHead "Git admin actions:"
menuItemClm 1 "Show local git config" localGitConfig 2 "Show global git config" globalGitConfig
Expand All @@ -39,10 +39,9 @@ menuItemClm 5 "Git extras" gitExtras 6 "Change Git Passwords" gitPasswort
echo
submenuHead "Shortcuts"
menuItemClm P "Change project" changeProject B "Change branch" changeBranch
menuItemClm F "Fetch all" fetachAll C "Compile favorites" compileMenu
menuItem X "Purge cache" purgeCash
menuItem F "Fetch all" fetachAll
echo
showStatus
choice
done
echo "bye, bye, homie!"
echo "bye, bye, homie!"
13 changes: 13 additions & 0 deletions EasyKey.maven/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EasyKey.maven utility

EasyKey.maven is a sample menu used for daily work with Maven. Here is the menu:

<img width="574" alt="image" src="https://github.com/nschlimm/EasyKey.shellmenu/assets/876604/37f76f5e-55af-445a-987d-b2787473a057">

# Get started

To get startet with the full functionality:

1. Install `mvn` (Maven) on the command line.
2. Clone this repository using `git clone https://github.com/nschlimm/EasyKey.shellmenu.git`
3. Start the menu with `bash maven.sh` or with `bash path/to/maven.sh`
48 changes: 46 additions & 2 deletions shellmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ choice () {
echo
echo "Press 'q' to quit"
echo
read -p "Make your choice: " -n 1 -r
echo -n "Your choice: " && wait_for_keypress
echo

if [[ $REPLY == "q" ]]; then
Expand All @@ -495,7 +495,7 @@ choice () {
importantLog "Huh ($REPLY)?"
fi
if $waitstatus; then
read -p $'\n<Press any key to return>' -n 1 -r
echo -n "<Press any key to return>" && wait_for_keypress
else
waitonexit # back to default after method execution
fi
Expand Down Expand Up @@ -624,3 +624,47 @@ draw_rounded_square() {

}

######################################################
# Reading single key input that works on most
# shells. Usage example:
# echo -n "Your choice: " && wait_for_keypress
# Outputs:
# REPLY - contains user selection (the key pressed)
######################################################
wait_for_keypress() {
stty raw
REPLY=$(dd bs=1 count=1 2> /dev/null)
stty -raw
}

######################################################
# A magic function that reads a file with sections
# into global arrays named by this section.
# Sections in the file start with [<section name>].
# After that section heading the config lines follow.
# A new section begins with [<new section name>].
# Arguments:
# $1: the config filename to read
# Outputs:
# Global arrays that have the name of the sections
# in the config file.
######################################################
initConfig () {
# read config to global arrays
INPUT="$1"
[ ! -f "$INPUT" ] && { echo "Config file not found: $INPUT"; wait_for_keypress; }
i=0
configlines=$(cat "$INPUT")
while read -r configline; do
if echo "$configline" | grep -q "\[.*\]"; then
configsection=$(echo "$configline" | grep -o "\[.*\]")
configsectioname=${configsection:1:${#configsection}-2}
i=0
continue
fi
if [ -n "$configline" ]; then
eval "${configsectioname}+=('$configline')"
fi
((i++))
done <<< "$(echo -e "$configlines")"
}

0 comments on commit dbddf0b

Please sign in to comment.