From d6686dbd03f308dc9d8f54e8e955212e582c8218 Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Thu, 28 Aug 2025 16:11:06 +1000 Subject: [PATCH] getpunk.cmd fix to allow in base dir and be checked in --- getpunk.cmd | 23 +++++++++++++++++++---- src/scriptapps/getpunk.bash | 15 ++++++++++++--- src/scriptapps/getpunk.ps1 | 8 +++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/getpunk.cmd b/getpunk.cmd index 6618d9cd..18708078 100644 --- a/getpunk.cmd +++ b/getpunk.cmd @@ -630,6 +630,8 @@ echo "script: $0" echo "pwd: $(pwd)" echo "scriptdir: $scriptdir" echo "scriptpath: $scriptpath" +scriptdir=$(realpath $scriptdir) +scriptpath=$(realpath $scriptpath) basename=$(basename "$scriptpath") scriptroot="${basename%.*}" #e.g "getpunk" @@ -648,13 +650,15 @@ if [[ "$launchdir" != "$scriptdir" ]]; then else punkfolder=$scriptdir fi +cd $punkfolder + contentcount=$(ls -A | wc -l) effectively_empty=0 if [ $contentcount == 0 ]; then effectively_empty=1 -elif [[ ("$punkfolder" == "$scriptfolder") && ("$contentcount" -lt 10) ]]; then +elif [[ ("$punkfolder" == "$scriptdir") && ("$contentcount" -lt 10) ]]; then #treat as empty if we have only a few files matching script root name - count_scriptlike=$(ls ${basename}.* | wc -l) + count_scriptlike=$(ls ${scriptroot}.* | wc -l) if [ "$count_scriptlike" -eq $contentcount ]; then effectively_empty=1 fi @@ -677,13 +681,18 @@ if [ "$effectively_empty" -ne 1 ]; then fi fi -cd $punkfolder if ! [ -d "$punkfolder/.git" ]; then #set defaultbranch to master to suppress loud stderr 'hint' about initial branch name. git -c init.DefaultBranch=master init git remote add origin $git_upstream fi git fetch origin +if [[ "$punkfolder" == "$scriptdir" ]]; then + if [ -f $scriptroot.cmd ]; then + cp -f $scriptroot.cmd $scriptroot.cmd.lastrun + rm $scriptroot.cmd + fi +fi git pull $git_upstream master git branch --set-upstream-to=origin/master master @@ -909,6 +918,7 @@ $git_upstream = "https://www.gitea1.intx.com.au/jn/punkshell" $launchdir = Get-Location #store original CWD $scriptfolder = Resolve-Path (Split-Path -Path $PSCommandPath -Parent) $punkfolder = "" +$scriptroot = "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath))" if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) { Write-Host "The git command doesn't seem to be available. Will attempt to install using winget." @@ -974,7 +984,7 @@ if ($contentcount -eq 0) { $effectively_empty = 1 } elseif ($punkfolder -eq $scriptfolder -and $contentcount -lt 10) { #treat as empty if we have only a few files matching script root name - $scriptlike = get-childitem -Path $punkfolder | Where-Object {$_.name -like "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)).*"} + $scriptlike = get-childitem -Path $punkfolder | Where-Object {$_.name -like "${scriptroot}.*"} if ($scriptlike.Count -eq $contentcount) { $effectively_empty = 1 } @@ -1005,6 +1015,11 @@ if (-not(Test-Path -Path (Join-Path -Path $punkfolder -ChildPath ".git") -PathTy git remote add origin $git_upstream } git fetch origin +if (($launchdir.Path) -eq ($scriptfolder.Path)) { + if (Test-Path -Path "${scriptroot}.cmd") { + Rename-Item -Path "${scriptroot}.cmd" -NewName "${scriptroot}.cmd.lastrun" -Force + } +} git pull $git_upstream master git branch --set-upstream-to=origin/master master diff --git a/src/scriptapps/getpunk.bash b/src/scriptapps/getpunk.bash index 36c34ea6..da32946c 100644 --- a/src/scriptapps/getpunk.bash +++ b/src/scriptapps/getpunk.bash @@ -17,6 +17,8 @@ echo "script: $0" echo "pwd: $(pwd)" echo "scriptdir: $scriptdir" echo "scriptpath: $scriptpath" +scriptdir=$(realpath $scriptdir) +scriptpath=$(realpath $scriptpath) basename=$(basename "$scriptpath") scriptroot="${basename%.*}" #e.g "getpunk" @@ -35,13 +37,15 @@ if [[ "$launchdir" != "$scriptdir" ]]; then else punkfolder=$scriptdir fi +cd $punkfolder + contentcount=$(ls -A | wc -l) effectively_empty=0 if [ $contentcount == 0 ]; then effectively_empty=1 -elif [[ ("$punkfolder" == "$scriptfolder") && ("$contentcount" -lt 10) ]]; then +elif [[ ("$punkfolder" == "$scriptdir") && ("$contentcount" -lt 10) ]]; then #treat as empty if we have only a few files matching script root name - count_scriptlike=$(ls ${basename}.* | wc -l) + count_scriptlike=$(ls ${scriptroot}.* | wc -l) if [ "$count_scriptlike" -eq $contentcount ]; then effectively_empty=1 fi @@ -64,13 +68,18 @@ if [ "$effectively_empty" -ne 1 ]; then fi fi -cd $punkfolder if ! [ -d "$punkfolder/.git" ]; then #set defaultbranch to master to suppress loud stderr 'hint' about initial branch name. git -c init.DefaultBranch=master init git remote add origin $git_upstream fi git fetch origin +if [[ "$punkfolder" == "$scriptdir" ]]; then + if [ -f $scriptroot.cmd ]; then + cp -f $scriptroot.cmd $scriptroot.cmd.lastrun + rm $scriptroot.cmd + fi +fi git pull $git_upstream master git branch --set-upstream-to=origin/master master diff --git a/src/scriptapps/getpunk.ps1 b/src/scriptapps/getpunk.ps1 index 734f9f2c..d01c9091 100644 --- a/src/scriptapps/getpunk.ps1 +++ b/src/scriptapps/getpunk.ps1 @@ -10,6 +10,7 @@ $git_upstream = "https://www.gitea1.intx.com.au/jn/punkshell" $launchdir = Get-Location #store original CWD $scriptfolder = Resolve-Path (Split-Path -Path $PSCommandPath -Parent) $punkfolder = "" +$scriptroot = "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath))" if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) { Write-Host "The git command doesn't seem to be available. Will attempt to install using winget." @@ -75,7 +76,7 @@ if ($contentcount -eq 0) { $effectively_empty = 1 } elseif ($punkfolder -eq $scriptfolder -and $contentcount -lt 10) { #treat as empty if we have only a few files matching script root name - $scriptlike = get-childitem -Path $punkfolder | Where-Object {$_.name -like "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)).*"} + $scriptlike = get-childitem -Path $punkfolder | Where-Object {$_.name -like "${scriptroot}.*"} if ($scriptlike.Count -eq $contentcount) { $effectively_empty = 1 } @@ -106,6 +107,11 @@ if (-not(Test-Path -Path (Join-Path -Path $punkfolder -ChildPath ".git") -PathTy git remote add origin $git_upstream } git fetch origin +if (($launchdir.Path) -eq ($scriptfolder.Path)) { + if (Test-Path -Path "${scriptroot}.cmd") { + Rename-Item -Path "${scriptroot}.cmd" -NewName "${scriptroot}.cmd.lastrun" -Force + } +} git pull $git_upstream master git branch --set-upstream-to=origin/master master