From 39734eff7cf1ef52e243db4f4ef90caac425bd0a Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Tue, 19 Mar 2024 16:59:25 +0100 Subject: [PATCH 01/16] First EasyKey.bash function to search text inside files --- EasyKey.bash/bashstuff.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 EasyKey.bash/bashstuff.sh diff --git a/EasyKey.bash/bashstuff.sh b/EasyKey.bash/bashstuff.sh new file mode 100644 index 0000000..dd422b9 --- /dev/null +++ b/EasyKey.bash/bashstuff.sh @@ -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)" From dde285a2ceb2b827be9df29ef6a263d8a5c28ff2 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Tue, 19 Mar 2024 18:06:11 +0100 Subject: [PATCH 02/16] Deleted favorites in EasyKey.git --- EasyKey.git/git.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/EasyKey.git/git.sh b/EasyKey.git/git.sh index ca93362..58c1cfe 100755 --- a/EasyKey.git/git.sh +++ b/EasyKey.git/git.sh @@ -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!" \ No newline at end of file +echo "bye, bye, homie!" From d347d2e10a9d23376a31469fa2cb0af94384a9ae Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Tue, 19 Mar 2024 19:56:46 +0100 Subject: [PATCH 03/16] Changes --- .gitignore | 1 + EasyKey.git/ezk-git-loca.sh | 30 +++--------------------------- 2 files changed, 4 insertions(+), 27 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35045ef --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +EasyKey.git/.ezk-git-loca-conf diff --git a/EasyKey.git/ezk-git-loca.sh b/EasyKey.git/ezk-git-loca.sh index ca7da4d..d41f072 100644 --- a/EasyKey.git/ezk-git-loca.sh +++ b/EasyKey.git/ezk-git-loca.sh @@ -33,7 +33,7 @@ initConfig () { continue fi if [ -n "$configline" ]; then - eval "${configsectioname[i]}='$configline'" + eval "${configsectioname}+=('$configline')" fi ((i++)) done <<< "$(echo -e "$configlines")" @@ -44,28 +44,7 @@ initConfig 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 @@ -88,6 +67,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 @@ -97,14 +77,10 @@ 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 From 4cf4b00cc107b40af6d1b38114eb7c89c2697d4d Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Tue, 19 Mar 2024 20:29:20 +0100 Subject: [PATCH 04/16] Added locations script --- EasyKey.git/ezk-locations.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 EasyKey.git/ezk-locations.sh diff --git a/EasyKey.git/ezk-locations.sh b/EasyKey.git/ezk-locations.sh new file mode 100644 index 0000000..a93a3c4 --- /dev/null +++ b/EasyKey.git/ezk-locations.sh @@ -0,0 +1,8 @@ +wait_for_keypress() { + stty raw + REPLY=$(dd bs=1 count=1 2> /dev/null) + stty -raw +} + +wait_for_keypress +echo "$REPLY" From dfbd12a29cc965febd7a386e3bbc7aee41111a30 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 11:22:12 +0100 Subject: [PATCH 05/16] New function to read user input that works cross platform --- EasyKey.git/ezk-locations.sh | 2 +- shellmenu.sh | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/EasyKey.git/ezk-locations.sh b/EasyKey.git/ezk-locations.sh index a93a3c4..cea7e46 100644 --- a/EasyKey.git/ezk-locations.sh +++ b/EasyKey.git/ezk-locations.sh @@ -4,5 +4,5 @@ wait_for_keypress() { stty -raw } -wait_for_keypress +echo -n "Make your choice: " && wait_for_keypress echo "$REPLY" diff --git a/shellmenu.sh b/shellmenu.sh index 89982a6..6c209f2 100644 --- a/shellmenu.sh +++ b/shellmenu.sh @@ -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 @@ -495,7 +495,7 @@ choice () { importantLog "Huh ($REPLY)?" fi if $waitstatus; then - read -p $'\n' -n 1 -r + echo -n "" && wait_for_keypress else waitonexit # back to default after method execution fi @@ -624,3 +624,15 @@ 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 +} \ No newline at end of file From 124a69f1bd681c3d2d5f9ee3dfaeeb6672305535 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 11:59:17 +0100 Subject: [PATCH 06/16] initConfig function moved to central shellmenu.sh for re-use by clients --- EasyKey.git/ezk-git-functions.sh | 1 + EasyKey.git/ezk-git-loca.sh | 26 +++--------------------- shellmenu.sh | 34 +++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/EasyKey.git/ezk-git-functions.sh b/EasyKey.git/ezk-git-functions.sh index c67b537..c24cc50 100644 --- a/EasyKey.git/ezk-git-functions.sh +++ b/EasyKey.git/ezk-git-functions.sh @@ -287,6 +287,7 @@ function atlassiansView() { function changeProject () { source $script_dir/../EasyKey.git/ezk-git-loca.sh + noterminate nowaitonexit } diff --git a/EasyKey.git/ezk-git-loca.sh b/EasyKey.git/ezk-git-loca.sh index d41f072..36ada0a 100644 --- a/EasyKey.git/ezk-git-loca.sh +++ b/EasyKey.git/ezk-git-loca.sh @@ -19,27 +19,9 @@ 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}+=('$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})) @@ -79,8 +61,6 @@ done if $uncached; then coloredLog "NEW" "1;42"; else coloredLog "CACHED" "1;42"; fi submenuHead "Shortcuts" menuItem X "Purge git dir cache" purgDirCache -echo -menuItem q "Quit" quit choice unset locations workspaces diff --git a/shellmenu.sh b/shellmenu.sh index 6c209f2..906ac83 100644 --- a/shellmenu.sh +++ b/shellmenu.sh @@ -635,4 +635,36 @@ wait_for_keypress() { stty raw REPLY=$(dd bs=1 count=1 2> /dev/null) stty -raw -} \ No newline at end of file +} + +###################################################### +# A magic function that reads a file with sections +# into global arrays named by this section. +# Sections in the file start with [
]. +# After that section heading the config lines follow. +# A new section begins with []. +# 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 "$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}+=('$configline')" + fi + ((i++)) + done <<< "$(echo -e "$configlines")" +} From dea41461423055fc01a80bff57fa0b3cde29eea3 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 13:07:50 +0100 Subject: [PATCH 07/16] Added locations script to EasyKey.bash --- EasyKey.bash/ezk-locations.sh | 44 +++++++++++++++++++++++++++++++++++ EasyKey.git/ezk-locations.sh | 8 ------- shellmenu.sh | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 EasyKey.bash/ezk-locations.sh delete mode 100644 EasyKey.git/ezk-locations.sh diff --git a/EasyKey.bash/ezk-locations.sh b/EasyKey.bash/ezk-locations.sh new file mode 100644 index 0000000..79bd61f --- /dev/null +++ b/EasyKey.bash/ezk-locations.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +unset locations + +script_dir="$1" +source "${script_dir}/shellmenu.sh" + +configfilename=.ezk-git-loca-conf + +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.git/${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 \ No newline at end of file diff --git a/EasyKey.git/ezk-locations.sh b/EasyKey.git/ezk-locations.sh deleted file mode 100644 index cea7e46..0000000 --- a/EasyKey.git/ezk-locations.sh +++ /dev/null @@ -1,8 +0,0 @@ -wait_for_keypress() { - stty raw - REPLY=$(dd bs=1 count=1 2> /dev/null) - stty -raw -} - -echo -n "Make your choice: " && wait_for_keypress -echo "$REPLY" diff --git a/shellmenu.sh b/shellmenu.sh index 906ac83..37d22eb 100644 --- a/shellmenu.sh +++ b/shellmenu.sh @@ -652,7 +652,7 @@ wait_for_keypress() { initConfig () { # read config to global arrays INPUT="$1" - [ ! -f "$INPUT" ] && { echo "$INPUT file not found"; exit 99; } + [ ! -f "$INPUT" ] && { echo "Config file not found: $INPUT"; wait_for_keypress; } i=0 configlines=$(cat "$INPUT") while read -r configline; do From 48ab73b387c5dd68f25545ff246371f067893354 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 13:11:46 +0100 Subject: [PATCH 08/16] Added config file for EasyKey.bash quick locations script --- EasyKey.bash/.ezk-bash-config | 4 ++++ EasyKey.bash/ezk-locations.sh | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 EasyKey.bash/.ezk-bash-config diff --git a/EasyKey.bash/.ezk-bash-config b/EasyKey.bash/.ezk-bash-config new file mode 100644 index 0000000..f442463 --- /dev/null +++ b/EasyKey.bash/.ezk-bash-config @@ -0,0 +1,4 @@ +[locations] +mavenhome=~/.m2 +workspace=~/workspace +easykey=~/workspace/EasyKey.shellmenu diff --git a/EasyKey.bash/ezk-locations.sh b/EasyKey.bash/ezk-locations.sh index 79bd61f..f89bf9c 100644 --- a/EasyKey.bash/ezk-locations.sh +++ b/EasyKey.bash/ezk-locations.sh @@ -5,7 +5,7 @@ unset locations script_dir="$1" source "${script_dir}/shellmenu.sh" -configfilename=.ezk-git-loca-conf +configfilename=.ezk-bash-config function toDirAndTerminate () { vars="$*" # all splitted words back to one var @@ -16,7 +16,7 @@ function toDirAndTerminate () { # Reads the config into global array "workspaces" # The config needs to have that section [workspaces] -initConfig "${script_dir}/EasyKey.git/${configfilename}" +initConfig "${script_dir}/EasyKey.bash/${configfilename}" echo "${locations[@]}" From 0a56ece1eb3ddffc7cdaaccf511ea3653dd8a7a9 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 13:13:24 +0100 Subject: [PATCH 09/16] Update .ezk-git-loca-conf --- EasyKey.git/.ezk-git-loca-conf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/EasyKey.git/.ezk-git-loca-conf b/EasyKey.git/.ezk-git-loca-conf index b4f37ae..2dcf894 100644 --- a/EasyKey.git/.ezk-git-loca-conf +++ b/EasyKey.git/.ezk-git-loca-conf @@ -1,7 +1,3 @@ [workspaces] myworkspacelocation=~/workspace -[locations] -mavenrepohome=~/.m2 -userbin=/usr/local/bin - From 9c97a6ddfd3f2b892bd78cde5f301212694d39fc Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:22:18 +0100 Subject: [PATCH 10/16] New EasyKey.git function to reduce repo size --- EasyKey.git/ezk-git-functions.sh | 12 ++++++++++++ EasyKey.git/git.sh | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/EasyKey.git/ezk-git-functions.sh b/EasyKey.git/ezk-git-functions.sh index c24cc50..55e3763 100644 --- a/EasyKey.git/ezk-git-functions.sh +++ b/EasyKey.git/ezk-git-functions.sh @@ -366,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" +} diff --git a/EasyKey.git/git.sh b/EasyKey.git/git.sh index 58c1cfe..1cdb871 100755 --- a/EasyKey.git/git.sh +++ b/EasyKey.git/git.sh @@ -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 From f2133ce70b8fa3fb5946ec56660ddf448ad1f403 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:26:01 +0100 Subject: [PATCH 11/16] Create README.md --- EasyKey.maven/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 EasyKey.maven/README.md diff --git a/EasyKey.maven/README.md b/EasyKey.maven/README.md new file mode 100644 index 0000000..b3c31d5 --- /dev/null +++ b/EasyKey.maven/README.md @@ -0,0 +1,3 @@ +# EasyKey.maven utility + +image From 790fbc5a9aa3ce4876cddc9b84b89e6cbf56a63e Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:27:09 +0100 Subject: [PATCH 12/16] Update README.md --- EasyKey.maven/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EasyKey.maven/README.md b/EasyKey.maven/README.md index b3c31d5..30a184f 100644 --- a/EasyKey.maven/README.md +++ b/EasyKey.maven/README.md @@ -1,3 +1,6 @@ # EasyKey.maven utility +EasyKey.maven is a sample menu used for daily work with Maven. Here is the menu: + image + From be7ce08b0f7e043f9fbe62af1ac6c07d99aff522 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:28:34 +0100 Subject: [PATCH 13/16] Update README.md --- EasyKey.maven/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/EasyKey.maven/README.md b/EasyKey.maven/README.md index 30a184f..3cf2da5 100644 --- a/EasyKey.maven/README.md +++ b/EasyKey.maven/README.md @@ -4,3 +4,10 @@ EasyKey.maven is a sample menu used for daily work with Maven. Here is the menu: image +# Get started + +To get startet with the full functionality: + +1. Install `mvn` (Maven) on the command line. +2. Clone this repository using `git clone ` +3. Start the menu with `bash maven.sh` or with `bash path/to/maven.sh` From 225c0ebc06a9bddbdf8b96e49843303431c774bf Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:29:04 +0100 Subject: [PATCH 14/16] Update README.md --- EasyKey.maven/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EasyKey.maven/README.md b/EasyKey.maven/README.md index 3cf2da5..4da0341 100644 --- a/EasyKey.maven/README.md +++ b/EasyKey.maven/README.md @@ -9,5 +9,5 @@ EasyKey.maven is a sample menu used for daily work with Maven. Here is the menu: To get startet with the full functionality: 1. Install `mvn` (Maven) on the command line. -2. Clone this repository using `git clone ` +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` From e74bfd79f7995e6f0958f367043bf2240568a996 Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:30:56 +0100 Subject: [PATCH 15/16] Create README.md --- EasyKey.bash/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 EasyKey.bash/README.md diff --git a/EasyKey.bash/README.md b/EasyKey.bash/README.md new file mode 100644 index 0000000..ad80907 --- /dev/null +++ b/EasyKey.bash/README.md @@ -0,0 +1,3 @@ +# EasyKey.bash utility + + From 9c013d7d21beb5a836c795ffea7e08ce5bba211b Mon Sep 17 00:00:00 2001 From: Niklas Schlimm Date: Wed, 20 Mar 2024 18:31:07 +0100 Subject: [PATCH 16/16] Update README.md --- EasyKey.bash/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EasyKey.bash/README.md b/EasyKey.bash/README.md index ad80907..056281c 100644 --- a/EasyKey.bash/README.md +++ b/EasyKey.bash/README.md @@ -1,3 +1,3 @@ # EasyKey.bash utility - +Experimental state of menu with usefull bash commands.