Last active
March 29, 2024 05:13
-
-
Save dingusagar/ffdc8e847a7be7e76b142a6488df7cb2 to your computer and use it in GitHub Desktop.
bashrc / zshrc Quick Sync when you login to a new machine.
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
#!/bin/bash -i | |
# What does this Script do ? | |
# Keep your most frequent bashrc / zshrc configs here. Now when you | |
# login to a new machine, instead of all the copy past hazzle, just | |
# run these commands to sync your bashrc/zshrc config file from here. | |
# RUN THE BELOW COMMAND FROM TERMINAL EVERYTIME YOU NEED TO SYNC. | |
# sh <(curl -sSL https://gist.githubusercontent.com/dingusagar/ffdc8e847a7be7e76b142a6488df7cb2/raw/rcsync.sh) | |
my_bash_conf=" | |
#START-DINGUS-REMOTE-BASH-SYNC | |
#------------------------- | |
# Ref to https://gist.githubusercontent.com/dingusagar/ffdc8e847a7be7e76b142a6488df7cb2/raw/rcsync.sh for this script. | |
# Git Aliases | |
alias gs='git status' | |
alias ga='git add' | |
alias gc='git commit -m' | |
alias gpo='git push origin' | |
alias gd='git diff' | |
alias gl='git log' | |
alias gb='git rev-parse --abbrev-ref HEAD' | |
alias gf='git fetch --all' | |
alias gck='git checkout ' | |
alias testalias='echo \"its working\"' | |
alias cs='sudo shutdown -c' # cancel shutdown | |
alias accrun='nohup mvn -Dtest=com.arintra.abacus.controllers.AccuracyControllerTest#evaluate test &' | |
alias sntrun='nohup mvn -Dtest=com.arintra.abacus.metric.sntaccuracy.SNTAccuracyTest#runSNT test &' | |
alias abcrun='nohup mvn -Dtest=com.arintra.abacus.conductors.AbacusConductorTest#validateLumenCase01 test &' | |
alias viacc='vim src/test/java/com/arintra/abacus/controllers/AccuracyControllerTest.java' | |
alias viabc='vim src/test/java/com/arintra/abacus/conductors/AbacusConductorTest.java' | |
alias viqaend='vim src/main/java/com/arintra/abacus/io/DLQuestionAnswerEndpoints.java' | |
alias tn='tail -f nohup.out' | |
alias tnl='tail -n 10000 nohup.out' | |
alias disableinference='python3 disableinference.py' | |
alias dingusync='zsh <(curl -sSL https://gist.githubusercontent.com/dingusagar/ffdc8e847a7be7e76b142a6488df7cb2/raw/rcsync.sh)' | |
#-------------------------- | |
#END-DINGUS-REMOTE-BASH-SYNC | |
" | |
# Function to update file content | |
update_file_content() { | |
local file_name="$1" | |
# Expand the tilde to get the absolute path | |
eval file_name="$file_name" | |
if [[ ! -f "$file_name" ]]; then | |
echo "File '$file_name' not found. Aborting sync for this file..." | |
return 1 | |
fi | |
# Use sed to find the line numbers for "REMOTE-SYNC" and "REMOTE-SYNC-END" | |
local start_line=$(grep -n "#START-DINGUS-REMOTE-BASH-SYNC" "$file_name" | cut -d ':' -f 1) | |
local end_line=$(grep -n "#END-DINGUS-REMOTE-BASH-SYNC" "$file_name" | cut -d ':' -f 1) | |
# If both start_line and end_line are found, proceed to modify the file | |
if [[ -n "$start_line" && -n "$end_line" ]]; then | |
echo "Detected existing section that can be updated" | |
# Use awk to delete lines between "REMOTE-SYNC" and "REMOTE-SYNC-END" | |
awk -v start="$start_line" -v end="$end_line" 'NR>=start && NR<=end {next} {print}' "$file_name" > "$file_name.tmp" | |
else | |
cp "$file_name" "$file_name.tmp" | |
fi | |
echo "Syncing settings to $file_name" | |
# Insert the new text using ex (non-interactive Vim) and the here document | |
ex -s "$file_name.tmp" <<EOF | |
i | |
$my_bash_conf | |
. | |
wq | |
EOF | |
# Replace the original file with the modified temporary file | |
mv "$file_name.tmp" "$file_name" | |
echo "Completed sync for $file_name" | |
echo "Run this command for the changes to reflect : source $file_name" | |
# source "$file_name" # some issue with this. | |
} | |
# Call the function with the filename argument (e.g., ~/.zshrc) | |
printf "Downloading and Syncing remote shell settings from https://gist.github.com/dingusagar/ffdc8e847a7be7e76b142a6488df7cb2/" | |
update_file_content "~/.zshrc" | |
update_file_content "~/.bashrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment