Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed Feb 6, 2023
1 parent e6cd4eb commit ee1927a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignoreglobal
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Editors
**/.dccache
# allow recommending extensions in repos
!**/.vscode/extensions.json
!.vscode/extensions.json
.vscode/*
.idea
Expand Down
12 changes: 8 additions & 4 deletions 4-aliases.rc
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ alias json-graph='colima start && docker run -p 8888:8080 jsonvisio && open http
# Backblaze
alias backblaze_edit='code /Library/Backblaze.bzpkg/bzdata/bzexcluderules_editable.xml'

# 3D printing (cura etc...)
alias cura='open -a /Applications/Ultimaker-Cura.app'
alias cura-backup='cp -r ~/Library/Application\ Support/cura/*.zip ~/Library/Mobile\ Documents/com~apple~CloudDocs/Backups/3dprinting/cura/'

alias scripts='cd ~/git/scripts'

### Suffix Aliases ###
Expand Down Expand Up @@ -176,3 +172,11 @@ alias modified-today="mdfind 'kMDItemFSContentChangeDate>\$time.today'"
if [[ "$OSTYPE" == "darwin"* ]]; then
alias lsusb='ioreg -p IOUSB -l -w 0'
fi

# 3D Printing

alias cura='open -a /Applications/Ultimaker-Cura.app'
alias cura-backup='cp -r ~/Library/Application\ Support/cura/*.zip ~/Library/Mobile\ Documents/com~apple~CloudDocs/Backups/3dprinting/cura/'

alias backup-models="rsync -avr --partial '/Users/samm/Library/Mobile Documents/com~apple~CloudDocs/3D Printing/Models' root@nas:/mnt/raid/3dprinting/"
alias backup-models-delete="rsync -avr --partial '/Users/samm/Library/Mobile Documents/com~apple~CloudDocs/3D Printing/Models' root@nas:/mnt/raid/3dprinting/ --delete"
57 changes: 57 additions & 0 deletions 9-functions.rc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,45 @@ function pr-checkout() {
fi
}

function git_add_global_prepush_hook() {
local repo_path=$1
local branch_name=$2
local hooks_path="$repo_path/.git/hooks"

# Check if the repo_path is a Git repository
if [ ! -d "$repo_path/.git" ]; then
echo "$repo_path is not a Git repository"
return 1
fi

# Create the pre-push hook if it doesn't exist
if [ ! -f "$hooks_path/pre-push" ]; then
touch "$hooks_path/pre-push"
chmod +x "$hooks_path/pre-push"
fi

# Add the code to the pre-push hook
cat << EOF >> "$hooks_path/pre-push"
#!/usr/bin/env bash

# This script can be run as a pre-push hook locally on repositories to add messages / ensure we're not pushing to the wrong branch etc...

branch_name=$(git symbolic-ref --short HEAD)
if [ "$branch_name" == "main" ] || [ "$branch_name" == "master" ]; then
echo "WARNING: You are pushing to the $branch_name branch!"
read -r -p "Are you sure you want to push to $branch_name? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$response - Pushing to $branch_name"
else
echo "Aborting push"
exit 1
fi
fi
EOF

echo "Global pre-push hook added to $repo_path"
}

# Gets the number of commits ahead from remote
function git_commits_ahead() {
if command git rev-parse --git-dir &>/dev/null; then
Expand Down Expand Up @@ -497,3 +536,21 @@ docker_login_ghcr(){

printf '{"Username":"%s", "Secret":"%s"}\n' "$(gh config get -h github.com user)" "${token}"
}


# 3D Printing
function cura-backup(){
# Zip up the latest cura config from the newest number cura config directory (~/Library/Application\ Support/cura/(number.number) (e.g. 4.8)
# and copy it to the cloud backup folder
local cura_base_dir="${HOME}/Library/Application Support/cura"
local destination="${HOME}/Library/Mobile Documents/com~apple~CloudDocs/Backups/3dprinting/cura"
local latest_version_dir="$(ls -d ${cura_base_dir}/*/ | tail -n1)"

# zip it up with the date
local date="$(date +%Y-%m-%d)"
local zip_file="${destination}/cura-${date}.zip"
zip -r "${zip_file}" "${latest_version_dir}"
echo "Created ${zip_file}"


}
15 changes: 15 additions & 0 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# This script can be run as a pre-push hook locally on repositories to add messages / ensure we're not pushing to the wrong branch etc...

branch_name=$(git symbolic-ref --short HEAD)
if [ "$branch_name" == "main" ] || [ "$branch_name" == "master" ]; then
echo "WARNING: You are pushing to the $branch_name branch!"
read -r -p "Are you sure you want to push to $branch_name? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Pushing to $branch_name"
else
echo "Aborting push"
exit 1
fi
fi

0 comments on commit ee1927a

Please sign in to comment.