From 3996045f93b203cfcf554381d3f3b4c29660ece3 Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Mon, 3 May 2021 14:37:49 +0200 Subject: [PATCH] further work on git auto save --- .config/custom_functions/git_auto_save.sh | 143 ++++++++++-------- .../polybar/config.ini##class.arch_desktop | 6 +- .terminal_aliases | 2 + .vimrc | 2 + .xmonad/xmonad.hs | 4 +- .xprofile##class.arch_desktop | 3 +- 6 files changed, 92 insertions(+), 68 deletions(-) diff --git a/.config/custom_functions/git_auto_save.sh b/.config/custom_functions/git_auto_save.sh index 5e4cc80..5fa1e43 100644 --- a/.config/custom_functions/git_auto_save.sh +++ b/.config/custom_functions/git_auto_save.sh @@ -4,100 +4,121 @@ 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 + if [[ $? != 0 ]]; then + return 0 + fi - return 1 + return 1 } function get_current_branch { - echo $(git branch | grep "*" | awk '{print $NF}') + echo $(git branch | grep "*" | awk '{print $NF}') } -function auto_save_git { +function git_auto_save { - if [[ $(is_git ".") -ne 0 ]]; then - echo "Current dir is not a git repository." - return 1 - fi + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi - current_branch_name=get_current_branch + 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 + 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 + # stash changes + git stash - # create new branch - git checkout -b $new_branch_name - git push origin $new_branch_name + # create new branch + git checkout -b $new_branch_name + git push origin $new_branch_name - # apply stashed changes - git stash apply + # apply stashed changes + git stash apply - # add changed files - git add -u + # add changed files + git add -u - # commit changes - git commit -m "git autosave from $timestamp" + # commit changes + git commit -m "git autosave from $timestamp" - # push changes - git push --set-upstream origin $new_branch_name + # push changes + git push --set-upstream origin $new_branch_name - # move back to initial branch - git checkout $current_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 - + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi + + if [[ $1 ]]; then + auto_save_branch=$1 + else auto_save_branch=`git branch | grep "git_auto_save" | head -1 | awk '{print $FN}'` + fi - if [[ ! $auto_save_branch ]]; then - echo "No auto save branch found." - return - fi + if [[ ! $auto_save_branch ]]; then + echo "No auto-save branch found." + return 1 + fi - auto_save_branch=${auto_save_branch:2} - current_branch=$(get_current_branch) + 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 + # 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 local branch + git branch -d $auto_save_branch - # remove remote branch - git push origin --delete $auto_save_branch + # remove remote branch + git push origin --delete $auto_save_branch + return 0 } function remove_all_auto_saves { + + if [[ $(is_git ".") -ne 0 ]]; then + echo "Current dir is not a git repository." + return 1 + fi + + if [[ $1 != "y" ]]; then + echo "Please confirm with 'y'" + return + fi + # remove all auto save branches - - if [[ $(is_git ".") -ne 0 ]]; then - echo "Current dir is not a git repository." - return 1 + while [[ 1 ]]; do + if ! remove_auto_save; then + break fi + echo "Auto-Save removed." + done - + echo "All auto-saves removed." } + +function load_last_auto_save { + echo "" +} diff --git a/.config/polybar/config.ini##class.arch_desktop b/.config/polybar/config.ini##class.arch_desktop index f84a7f7..877734d 100644 --- a/.config/polybar/config.ini##class.arch_desktop +++ b/.config/polybar/config.ini##class.arch_desktop @@ -121,8 +121,8 @@ padding = 0 ; Number of spaces to add before/after each module ; Individual side values can be defined using: ; module-margin-{left,right} -module-margin-left = 5 -module-margin-right = 5 +module-margin-left = 2 +module-margin-right = 2 ; Fonts are defined using ; ; Font names are specified using a fontconfig pattern. @@ -165,7 +165,7 @@ modules-center = title modules-right = pulseaudio mic_status network battery date ; The separator will be inserted between the output of each module -separator = +separator = | ; This value is used to add extra spacing between elements ; @deprecated: This parameter will be removed in an upcoming version diff --git a/.terminal_aliases b/.terminal_aliases index 4d502fd..4ae62c1 100644 --- a/.terminal_aliases +++ b/.terminal_aliases @@ -1,2 +1,4 @@ alias spotify='spotify --force-device-scale-factor=2' alias ll='ls -la --color=auto' + +alias hibernate='systemctl hibernate' diff --git a/.vimrc b/.vimrc index 3517011..2ce2ee3 100644 --- a/.vimrc +++ b/.vimrc @@ -12,6 +12,8 @@ set hidden set encoding=utf-8 set t_Co=256 set tabstop=4 +set softtabstop=0 noexpandtab +set shiftwidth=4 " enable search highlighting set hlsearch diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index 48fbb96..e1dee1c 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -94,8 +94,8 @@ green = "#859900" -- sizes gap = 10 -topbar = 5 -border = 0 +topbar = 0 +border = 2 prompt = 5 status = 5 diff --git a/.xprofile##class.arch_desktop b/.xprofile##class.arch_desktop index ec3bdf9..2ebf2cb 100644 --- a/.xprofile##class.arch_desktop +++ b/.xprofile##class.arch_desktop @@ -5,5 +5,4 @@ xrandr --dpi 110 sleep 5 && xset s 300 & -xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/logind-handle-lid-switch -n -t bool -s true -xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/logind-handle-power-key -n -t bool -s true +systemd-run --user --on-calendar=minutely --unit=polybar_auto_hide /usr/bin/polybar-msg cmd hide