Last active
April 10, 2025 14:09
-
-
Save whunter/103764a8554b630fccd647b345cda98f to your computer and use it in GitHub Desktop.
Shell script for saving stuff to github
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 characters
usage="Usage: . ./save.sh < filename | all | -n string | -b string>" | |
if [ -z "$1" ]; then | |
echo $usage | |
return | |
fi | |
savedDir='/path/to/your/git-repo' | |
randos="$savedDir/randos" | |
notes="$savedDir/notes.txt" | |
bookmarks="$savedDir/bookmarks.txt" | |
workingDir=$(pwd) | |
if [ "$1" = "all" ]; then | |
# save all files in current directory | |
collapsedPath="${PWD//\//-}" | |
echo "Saving errthing to $savedDir/$collapsedPath" | |
mkdir -p "$savedDir/$collapsedPath" | |
cp * "$savedDir/$collapsedPath" | |
elif [ -f "$1" ]; then | |
# save specific file | |
echo "Saving file $1 to $randos" | |
mkdir -p "$randos" | |
cp "$1" "$randos" | |
elif [ "$1" = "-n" ]; then | |
# append string input to notes.txt | |
echo "Saving note to $notes" | |
inputString=${@:2} | |
echo "$inputString" | |
echo "$inputString" >> "$notes" | |
elif [ "$1" = "-b" ]; then | |
# append url(string) to bookmarks.txt | |
echo "Saving url to $bookmarks" | |
inputString=${2} | |
echo "$inputString" | |
echo "$inputString" >> "$bookmarks" | |
else | |
echo "Not really sure what you're trying to do with: $1" | |
echo $usage | |
return | |
fi | |
# commit and push to git | |
if [ -d "$savedDir/.git" ]; then | |
cd $savedDir | |
git add . --all | |
git commit -m "Auto commit" | |
git push | |
cd $workingDir | |
else | |
echo "Not a git repository" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copies / appends (file(s) | urls < string > | freeform notes < string >) to local clone of git repo and pushes changes to remote.
Note: All save operations try to automatically commit all git changes and push them to git repo's remote after copy/append
1. Create or clone your git repo on your dev machine (if you're creating a repo you'll need to also create the corresponding "remote" repo)
git clone <your git-repo>
2. Save script to your development machine
3. Edit line 6 in save.sh to use the actual path to your local git clone
savedDir='/actual/path/to/your/local/git-repo'
4. Create an alias in your
~/.<shell>rc
or~/.aliases
or whatever init script:5. Source that init script:
. ~/.aliases # or whichever init script you chose
6. Then you can call the script by the alias name from any directory:
Again: All save operations try to automatically commit all git changes and push them to git repo's remote after copy/append
Example usage: