Last active
August 28, 2023 18:32
-
-
Save MarkWalters-dev/992616d92e2cfca8b8e999490f16c1fc to your computer and use it in GitHub Desktop.
Revisions
-
MarkWalters-dev revised this gist
Aug 28, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ l=$(grep "^#${gist_icon}" $f) gist_id=${gist_id% *} [ -n "$gist_id" ] || crash "Could not extract gist_id" [ -n "$gist_filename" ] || crash "Could not extract gist_id" echo Updating gist gh gist edit $gist_id -f $gist_filename $f || crash "gh update error" } || { shift -
MarkWalters-dev revised this gist
Aug 28, 2023 . 1 changed file with 24 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,21 @@ #!/usr/bin/env bash #🌩️ gist 992616d92e2cfca8b8e999490f16c1fc ghgist # Uses gh to create and update gists # TODO: # If .gist used then setup symlinks # Need method to gh gist clone without using a .gist folder # look for short description in file and use it # if short description is provided then insert in file # Short description always directly after gist id comment and an empty line # Complex gists might need a readme. # If .gist not used then .filename.readme.md or maybe .filename.md # actual gist filename of readme would be README.md # if used could also look for short description in readme # this might be useful if --help is used. You could mdcat the readme crash() { local err=$? @@ -17,15 +28,17 @@ command_exists() { return $? } f=$1 [ -f "$f" ] || { echo "Usage: $(basename ${BASH_SOURCE[0]}) FILENAME [DESCRIPTION IF NEW GIST]"; exit; } command_exists gh || crash "gh not installed" [ -e "$HOME/.config/gh/hosts.yml" ] || crash "gh not configured\nRun gh auth login" gist_icon="🌩️" # Unlikely I will find a line beginning with # and this symbol l=$(grep "^#${gist_icon}" $f) [ -n "$l" ] && { gist_id=${l#*${gist_icon} gist } gist_filename=${gist_id#* } # Does not support filenames with spaces gist_id=${gist_id% *} [ -n "$gist_id" ] || crash "Could not extract gist_id" [ -n "$gist_filename" ] || crash "Could not extract gist_id" echo existing gist @@ -35,14 +48,15 @@ gist_id=${gist_id% *} description="$*" [ -n "$description" ] || { echo "New gist requires a description"; exit; } gist_filename=${f##*/} # Same as using basename [ -n "$gist_filename" ] || crash "Error getting gist_filename" gist_id=$(gh gist create --public -d "$description" -f $f $f) || crash "gh create error" gist_id=${gist_id##*/} [ -n "$gist_id" ] || { gh gist list; crash "Error getting gist_id\nDo you see anything new?"; } # nix-script with nix-shell can use multiple shebang lines. last_shebang=$(grep -n "^#!" $f | tail -1 | cut -f1 -d:) [ -z "$last_shebang" ] && last_shebang=0 last_shebang=$(( last_shebang + 1 )) sed -i "${last_shebang}i\#${gist_icon} gist $gist_id $gist_filename" $f || crash "sed error" gh gist edit $gist_id -f $gist_filename $f || crash "gh update error" } -
MarkWalters-dev revised this gist
Aug 28, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #!/usr/bin/env bash #🌩️ gist 992616d92e2cfca8b8e999490f16c1fc ghgist f=$1 # TODO: -
MarkWalters-dev created this gist
Aug 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ #!/usr/bin/env bash f=$1 # TODO: # If .gist used then setup symlinks # Need method to clone without using a .gist folder crash() { local err=$? printf "%s\nCrashed at: %s:%s\n" "$*" "${FUNCNAME[1]}" "${BASH_LINENO[0]}" exit $err } command_exists() { command -v $1 > /dev/null 2>&1 return $? } command_exists gh || crash "gh not installed" [ -e "$HOME/.config/gh/hosts.yml" ] || crash "gh not configured\nRun gh auth login" [ -f "$f" ] || { echo "Usage: $(basename ${BASH_SOURCE[0]}) FILENAME [DESCRIPTION IF NEW GIST]"; exit; } l=$(grep "^#🌩️" $f) gist_id=${l#*🌩️ gist } gist_filename=${gist_id#* } # Does not support filenames with spaces gist_id=${gist_id% *} [ -n "$l" ] && { [ -n "$gist_id" ] || crash "Could not extract gist_id" [ -n "$gist_filename" ] || crash "Could not extract gist_id" echo existing gist gh gist edit $gist_id -f $gist_filename $f || crash "gh update error" } || { shift description="$*" [ -n "$description" ] || { echo "New gist requires a description"; exit; } gist_filename=${f##*/} # Same as using basename gist_id=$(gh gist create --public -d "$description" -f $f $f) || crash "gh create error" gist_id=${gist_id##*/} # nix-script with nix-shell can use multiple shebang lines. last_shebang=$(grep -n "^#!" $f | tail -1 | cut -f1 -d:) [ -z "$last_shebang" ] && last_shebang=0 last_shebang=$(( last_shebang + 1 )) sed -i "${last_shebang}i\#🌩️ gist $gist_id $gist_filename" $f gh gist edit $gist_id -f $gist_filename $f || crash "gh update error" } alternatemethod() { # Would require a dedicated .gist folder and symlinks to bin folder git init git remote add gist "$(gh gist create README.md)" git fetch gist git checkout -f master git add . && git commit -m "add the rest of the files" git push }