Last active
January 15, 2024 19:26
-
-
Save ViBiOh/d72d01a82c604a37afb7a2165a72ffba to your computer and use it in GitHub Desktop.
Revisions
-
ViBiOh revised this gist
Jun 17, 2020 . 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 @@ -21,7 +21,7 @@ head_sync() { local branch branch="$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')" ssh -A "${1}" "cd '${2}' && git reset HEAD . && git clean -f && git status -u -s | awk '{print \$2}' | xargs rm -rf && git checkout -- . && git fetch && git checkout '${branch}' && git pull" } git_sync() { -
ViBiOh revised this gist
Apr 28, 2020 . 1 changed file with 4 additions 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,5 +1,9 @@ #!/usr/bin/env bash git_is_inside() { git rev-parse --is-inside-work-tree 2>&1 } git_root() { if [[ $(git_is_inside) != "true" ]]; then pwd -
ViBiOh revised this gist
Apr 20, 2020 . 1 changed file with 38 additions and 42 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,60 +1,55 @@ #!/usr/bin/env bash git_root() { if [[ $(git_is_inside) != "true" ]]; then pwd return fi git rev-parse --show-toplevel } head_sync() { if [[ ${#} -ne 2 ]]; then printf "%bUsage: head_sync [REMOTE_SERVER] [REMOTE_PATH]%b\n" "${RED}" "${RESET}" return 1 fi local branch branch="$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')" ssh -A "${1}" "cd ${2} && git reset HEAD . && git clean -f && git status -u -s | awk '{print $2}' | xargs rm -rf && git checkout -- . && git fetch && git checkout ${branch} && git pull" } git_sync() { if [[ ${#} -lt 2 ]]; then printf "%bUsage: git_sync [REMOTE_SERVER] [REMOTE_PATH] [DRY]?%b\n" "${RED}" "${RESET}" return 1 fi git_root isGit=$? if [[ ${isGit} -ne 0 ]]; then return ${isGit} fi local REMOTE_PATH_PREFIX="~/${2}" if [[ ${2:0:1} == "/" ]]; then REMOTE_PATH_PREFIX="${2}" fi local dry=false if [[ $(echo "${3}" | tr "[:upper:]" "[:lower:]") == "dry" ]]; then dry=true fi if [[ ${dry} == true ]]; then printf "%bDry run of syncing files...%b\n" "${BLUE}" "${RESET}" else printf "%bSyncing files at %s...%b\n" "${BLUE}" "$(date +'%H:%M:%S')" "${RESET}" fi declare -a toSync declare -a toDelete local IFS=$'\n' for gitFile in $(git status --porcelain); do @@ -63,53 +58,54 @@ git_sync() { case "${trimmedPrefix:0:1}" in "M" | "A" | "?") toSync+=("${gitFile:3}") ;; "D") toDelete+=("${REMOTE_PATH_PREFIX}/${gitFile:3}") ;; "R") local originFile originFile="$(echo "${gitFile}" | awk '{print $2}')" local destinationFile destinationFile="$(echo "${gitFile}" | awk '{print $4}')" toDelete+=("${REMOTE_PATH_PREFIX}/${originFile}") toSync+=("${destinationFile}") ;; *) printf "%b¯\_(ツ)_/¯ Don't know how to handle ${gitFile}%b\n" "${BLUE}" "${RESET}" esac done if ! ${dry}; then printf "%bCleaning remote%b\n" "${YELLOW}" "${RESET}" ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git clean -f && git checkout -- ." fi if [[ ${#toDelete[@]} -ne 0 ]]; then ! ${dry} && ssh "${1}" "rm -rf ${toDelete[*]}" printf "%b- Deleted\n%s%b\n" "${RED}" "${toDelete[*]}" "${RESET}" fi if [[ ${#toSync[@]} -ne 0 ]]; then ! ${dry} && rsync -raR "${toSync[@]}" "${1}:${REMOTE_PATH_PREFIX}/" printf "%b+ Copied\n%s%b\n" "${GREEN}" "${toSync[*]}" "${RESET}" fi printf "%bDone at %s!%b\n\n" "${BLUE}" "$(date +'%H:%M:%S')" "${RESET}" } watch_sync() { if [[ -z ${NO_HEAD_SYNC:-} ]]; then head_sync "${@}" fi git_sync "${@}" fswatch -0 -o --exclude=.git/ . | while read -r -d "" do git_sync "${@}" done -
ViBiOh revised this gist
Mar 1, 2019 . 1 changed file with 1 addition and 9 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,15 +1,7 @@ #!/usr/bin/env bash git_root() { git rev-parse --is-inside-work-tree > /dev/null 2>&1 && cd $(git rev-parse --show-toplevel) } head_sync() { -
ViBiOh revised this gist
Feb 22, 2019 . 1 changed file with 17 additions and 13 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,5 +1,17 @@ #!/usr/bin/env bash git_root() { if ! $(git rev-parse --is-inside-work-tree 2>/dev/null); then return 1 else local gitRootDir=$(git rev-parse --show-cdup) if [[ -n "${gitRootDir}" ]]; then cd "${gitRootDir}" fi fi } head_sync() { if [[ "${#}" -ne 2 ]]; then echo "Usage: head_sync [REMOTE_SERVER] [REMOTE_PATH]" @@ -15,18 +27,6 @@ head_sync() { ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git reset HEAD . && git clean -f && git checkout -- . && git fetch && git checkout ${branch} && git pull" } git_sync() { if [[ "${#}" -lt 2 ]]; then echo "Usage: git_sync [REMOTE_SERVER] [REMOTE_PATH] [DRY]?" @@ -110,7 +110,11 @@ git_sync() { echo } watch_sync() { if [[ -z "${NO_HEAD_SYNC:-}" ]]; then head_sync "${@}" fi git_sync "${@}" fswatch -0 -o --exclude=.git/ . | while read -d "" event -
ViBiOh revised this gist
Feb 14, 2019 . 1 changed file with 32 additions and 25 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,23 +1,35 @@ #!/usr/bin/env bash head_sync() { if [[ "${#}" -ne 2 ]]; then echo "Usage: head_sync [REMOTE_SERVER] [REMOTE_PATH]" return 1 fi local REMOTE_PATH_PREFIX="~/${2}" if [[ "${2:0:1}" == "/" ]]; then REMOTE_PATH_PREFIX="${2}" fi local branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||') ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git reset HEAD . && git clean -f && git checkout -- . && git fetch && git checkout ${branch} && git pull" } git_root() { if ! $(git rev-parse --is-inside-work-tree 2>/dev/null); then return 1 else local gitRootDir=$(git rev-parse --show-cdup) if [[ -n "${gitRootDir}" ]]; then cd "${gitRootDir}" fi fi } git_sync() { if [[ "${#}" -lt 2 ]]; then echo "Usage: git_sync [REMOTE_SERVER] [REMOTE_PATH] [DRY]?" return 1 fi @@ -27,28 +39,23 @@ function git_sync() { local BLUE='\033[0;34m' local RESET='\033[0m' git_root isGit=$? if [[ ${isGit} -ne 0 ]]; then return ${isGit} fi local REMOTE_PATH_PREFIX="~/${2}" if [[ "${2:0:1}" == "/" ]]; then REMOTE_PATH_PREFIX="${2}" fi local dry=false if [[ "${3,,}" == "dry" ]]; then dry=true fi if [[ "${dry}" == true ]]; then echo -e "${BLUE}Dry run of syncing files...${RESET}\n" else echo -e "${BLUE}Syncing files...${RESET}\n" @@ -58,7 +65,7 @@ function git_sync() { local toDelete=() local IFS=$'\n' for gitFile in $(git status --porcelain); do local prefix="${gitFile:0:2}" local trimmedPrefix="${prefix#[[:space:]]}" @@ -72,8 +79,8 @@ function git_sync() { ;; "R") local originFile=$(echo -n "${gitFile}" | awk '{print $2}') local destinationFile=$(echo -n "${gitFile}" | awk '{print $4}') toDelete=("${toDelete[@]}" "${REMOTE_PATH_PREFIX}/${originFile}") toSync=("${toSync[@]}" "${destinationFile}") @@ -89,12 +96,12 @@ function git_sync() { ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git clean -f && git checkout -- ." fi if [[ "${#toDelete[@]}" -ne 0 ]]; then ! ${dry} && ssh "${1}" "rm -rf ${toDelete[@]}" echo -e "${RED} - Deleted\n${toDelete[*]}${RESET}\n" fi if [[ "${#toSync[@]}" -ne 0 ]]; then ! ${dry} && rsync -raR "${toSync[@]}" "${1}:${REMOTE_PATH_PREFIX}/" echo -e "${GREEN} + Copied\n${toSync[*]}${RESET}\n" fi -
ViBiOh revised this gist
Dec 19, 2018 . 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 @@ -12,7 +12,7 @@ function head_sync() { fi local branch=`git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||'` ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git reset HEAD . && git clean -f && git checkout -- . && git fetch && git checkout ${branch} && git pull" } function git_sync() { -
ViBiOh revised this gist
Mar 19, 2018 . 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 @@ -31,7 +31,7 @@ function git_sync() { echo -e "${RED}You're not inside a git folder${RESET}" return 1 else local gitRootDir=`git rev-parse --show-cdup` if [ -n "${gitRootDir}" ]; then cd "${gitRootDir}" -
ViBiOh revised this gist
Mar 19, 2018 . 1 changed file with 2 additions and 2 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 @@ -2,7 +2,7 @@ function head_sync() { if [ "${#}" -ne 2 ]; then echo Usage: head_sync [REMOTE_SERVER] [REMOTE_PATH] return 1 fi @@ -17,7 +17,7 @@ function head_sync() { function git_sync() { if [ "${#}" -lt 2 ]; then echo Usage: git_sync [REMOTE_SERVER] [REMOTE_PATH] [DRY]? return 1 fi -
ViBiOh revised this gist
Mar 19, 2018 . 1 changed file with 6 additions and 2 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 @@ -27,11 +27,15 @@ function git_sync() { local BLUE='\033[0;34m' local RESET='\033[0m' if ! `git rev-parse --is-inside-work-tree 2>/dev/null`; then echo -e "${RED}You're not inside a git folder${RESET}" return 1 else gitRootDir=`git rev-parse --show-cdup` if [ -n "${gitRootDir}" ]; then cd "${gitRootDir}" fi fi local REMOTE_PATH_PREFIX="~/${2}" -
ViBiOh created this gist
Mar 19, 2018 .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,109 @@ #!/usr/bin/env bash function head_sync() { if [ "${#}" -ne 2 ]; then echo Usage: head_sync [REMOTE_SERVER] [REMOTE_PATH_FROM_HOME] return 1 fi local REMOTE_PATH_PREFIX="~/${2}" if [ "${2:0:1}" == "/" ]; then REMOTE_PATH_PREFIX="${2}" fi local branch=`git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||'` ssh "${1}" "PS1=$ source ~/.bashrc && cd ${REMOTE_PATH_PREFIX} && git reset HEAD . && git clean -f && git checkout -- . && git fetch && git checkout ${branch} && git pull" } function git_sync() { if [ "${#}" -lt 2 ]; then echo Usage: git_sync [REMOTE_SERVER] [REMOTE_PATH_FROM_HOME] [DRY]? return 1 fi local RED='\033[0;31m' local GREEN='\033[0;32m' local YELLOW='\033[0;33m' local BLUE='\033[0;34m' local RESET='\033[0m' if ! `git rev-parse --is-inside-work-tree`; then echo -e "${RED}You're not inside a git folder${RESET}" return 1 else cd `git rev-parse --show-cdup` fi local REMOTE_PATH_PREFIX="~/${2}" if [ "${2:0:1}" == "/" ]; then REMOTE_PATH_PREFIX="${2}" fi local dry=false if [ "${3,,}" == "dry" ]; then dry=true fi if ${dry}; then echo -e "${BLUE}Dry run of syncing files...${RESET}\n" else echo -e "${BLUE}Syncing files...${RESET}\n" fi local toSync=() local toDelete=() local IFS=$'\n' for gitFile in `git status --porcelain`; do local prefix="${gitFile:0:2}" local trimmedPrefix="${prefix#[[:space:]]}" case "${trimmedPrefix:0:1}" in "M" | "A" | "?") toSync=("${toSync[@]}" "${gitFile:3}") ;; "D") toDelete=("${toDelete[@]}" "${REMOTE_PATH_PREFIX}/${gitFile:3}") ;; "R") local originFile=`echo -n "${gitFile}" | awk '{print $2}'` local destinationFile=`echo -n "${gitFile}" | awk '{print $4}'` toDelete=("${toDelete[@]}" "${REMOTE_PATH_PREFIX}/${originFile}") toSync=("${toSync[@]}" "${destinationFile}") ;; *) echo -e "${BLUE} ¯\_(ツ)_/¯ Don't know how to handle ${gitFile}${RESET}" esac done if ! ${dry}; then echo -e "${YELLOW}Cleaning remote${RESET}\n" ssh "${1}" "cd ${REMOTE_PATH_PREFIX} && git clean -f && git checkout -- ." fi if [ "${#toDelete[@]}" -ne 0 ]; then ! ${dry} && ssh "${1}" "rm -rf ${toDelete[@]}" echo -e "${RED} - Deleted\n${toDelete[*]}${RESET}\n" fi if [ "${#toSync[@]}" -ne 0 ]; then ! ${dry} && rsync -raR "${toSync[@]}" "${1}:${REMOTE_PATH_PREFIX}/" echo -e "${GREEN} + Copied\n${toSync[*]}${RESET}\n" fi echo -e "${BLUE}Done!${RESET}" echo } function watch_sync() { git_sync "${@}" fswatch -0 -o --exclude=.git/ . | while read -d "" event do git_sync "${@}" done }