diff --git a/.config/custom_functions/git_auto_save.sh b/.config/custom_functions/git_auto_save.sh new file mode 100644 index 0000000..5e4cc80 --- /dev/null +++ b/.config/custom_functions/git_auto_save.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +function is_git { + + # check if current folder is git repository + git_check_command=$(git -C $1 rev-parse > /dev/null 2>&1) + if [[ $? != 0 ]]; then + return 0 + fi + + return 1 +} + +function get_current_branch { + echo $(git branch | grep "*" | awk '{print $NF}') +} + +function auto_save_git { + + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi + + current_branch_name=get_current_branch + + timestamp=`date +%Y_%m_%d_%H_%M_%S` + new_branch_name="git_auto_save/$HOST/$timestamp" + + # check if there is unsaved work + changes=`git status --ignore-submodules=dirty | grep -E 'modified|deleted|new'` + if [[ ! $changes ]]; then + echo "No changes found." + return + fi + + # stash changes + git stash + + # create new branch + git checkout -b $new_branch_name + git push origin $new_branch_name + + # apply stashed changes + git stash apply + + # add changed files + git add -u + + # commit changes + git commit -m "git autosave from $timestamp" + + # push changes + git push --set-upstream origin $new_branch_name + + # move back to initial branch + git checkout $current_branch_name + +} + +function remove_auto_save { + + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi + + auto_save_branch=`git branch | grep "git_auto_save" | head -1 | awk '{print $FN}'` + + if [[ ! $auto_save_branch ]]; then + echo "No auto save branch found." + return + fi + + auto_save_branch=${auto_save_branch:2} + current_branch=$(get_current_branch) + + # if on autosave branch, move to master + if [[ $current_branch == $auto_save_branch ]]; then + echo "Currently on autosave path, moving to Master" + git checkout master + fi + + # remove local branch + git branch -d $auto_save_branch + + # remove remote branch + git push origin --delete $auto_save_branch + + +} + +function remove_all_auto_saves { + # remove all auto save branches + + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi + + + +} diff --git a/.custom_functions b/.custom_functions index 9dc34b8..afba17b 100644 --- a/.custom_functions +++ b/.custom_functions @@ -1,3 +1,8 @@ +#!/bin/bash + +custom_func_dir=$HOME/.config/custom_functions +for f in $custom_func_dir/*; do source $f; done + function connectToStorageVM() { ssh alex@173.212.206.52 } diff --git a/.tmux.conf b/.tmux.conf index 952aaec..47c399b 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -49,7 +49,7 @@ set-option -g status-right-length 90 set-option -g status-left "#(~/.config/tmux-powerline/powerline.sh left)" set-option -g status-right "#(~/.config/tmux-powerline/powerline.sh right)" -source "/usr/lib/python3.9/site-packages/powerline/bindings/tmux/powerline.conf" +source "$HOME/.local/lib/python3.9/site-packages/powerline/bindings/tmux/powerline.conf" # clear both screen and history diff --git a/.vimrc b/.vimrc index 781aba9..3517011 100644 --- a/.vimrc +++ b/.vimrc @@ -30,6 +30,12 @@ nmap W :q! nmap vs :vs nmap hs :hs +" copy to system clipboard +set clipboard=unnamedplus +noremap y "*y +noremap p "*p +noremap Y "+y +noremap P "+p " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim