Skip to content

Instantly share code, notes, and snippets.

@hsayed21
Last active August 25, 2021 01:25
Show Gist options
  • Save hsayed21/907a492818b247638c2848d4d6b43a15 to your computer and use it in GitHub Desktop.
Save hsayed21/907a492818b247638c2848d4d6b43a15 to your computer and use it in GitHub Desktop.

For Windows

Tools Used:

after install git make file call.bat contains bash_git path and the shell_script file that we want to run it from windows using batch script

cmd /c ""C:\Program Files\Git\bin\bash.exe" --login -i -- H:\myshell.sh"

after that goto obsidian workspace folder create file .gitignore

# To ignore files that could cause issues across different workspaces
nano .gitignore
# and set these 3 lines in
.obsidian/cache
.trash/
.DS_Store

then create file .gitattributes this file used to fix merge conflict automatically through keep both ours and theirs when conflict

# Add a line to .gitattributes:
*.md merge=union

initialize repo

git init
git add .
git commit -m "init"
git remote add origin https://github.com/USER/REPONAME.git
# To permanently cache the credentials
git config --global credential.helper store
git push -u origin master

Task Scheduler make shell script file obsidian_git.sh

# Making a new script to automate our repo management
touch obsidian_git.sh 
chmod +x obsidian_git.sh 

obsidian_git.sh

#!/usr/bin/env sh

VAULT_PATH="/c/Users/H/Documents/myObsidianWorkspace"
cd "$VAULT_PATH"

# infinite loop repeat each 30 minutes 
while true 
do 
 git pull > /dev/null 2>&1
 CHANGES_EXIST="$(git status --porcelain | wc -l)"
 
 # check if $CHANGES_EXIST Not equal to zero that means there is some changes on obsidian files
 if [ "$CHANGES_EXIST" -ne 0 ]; then

 git pull > /dev/null 2>&1
 git add . 
 git commit -q -m "Last Sync: $(date +"%Y-%m-%d %H:%M:%S")" 
 git push -q
 
 fi

 # sleep 30 minutes then repeat again!
 sleep 30m

done

To run script automatic when system startup and hidden cmd console, fist create vbs file run.vbs and set these lines in

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Users\H\Documents\myObsidianWorkspace\call.bat" & Chr(34), 0
Set WshShell = Nothing

here should you change this path to your file path batch script file that we create on top section C:\Users\H\Documents\myObsidianWorkspace\call.bat

after that goto startup folder through shortcut keyboard Win+R to open run window type=> shell:startup automatic will open startup folder, last step copy run.vbs file there

every time system start the script will be run

For Android

Tools Used:

generate token authentication for github to login with it on android automatic without authentication each time

Settings> Developer settings > Personal access token

open termux then run this command to access storage termux-setup-storage clone your repo with token authentication cd storage/shared/ git clone https://token_name:token_key@github.com/username/my_workspace

change VAULT_Path in obsidian_git.sh with path your workspace in android in termux run command pwd to get current path then copy it and paste in obsidian_git.sh

to run script bash obsidian_git.sh will run automatic 😀 in background

for explore files and modify use obsidian app on android

that's it everything done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment