diff options
Diffstat (limited to 'ar/.local/bin')
| -rwxr-xr-x | ar/.local/bin/gitopenbranch | 3 | ||||
| -rwxr-xr-x | ar/.local/bin/rbackup | 52 | ||||
| -rwxr-xr-x | ar/.local/bin/shortcuts | 27 | ||||
| -rwxr-xr-x | ar/.local/bin/statusbar/sb-repos | 55 |
4 files changed, 105 insertions, 32 deletions
diff --git a/ar/.local/bin/gitopenbranch b/ar/.local/bin/gitopenbranch index 56c8d12..a3a32d4 100755 --- a/ar/.local/bin/gitopenbranch +++ b/ar/.local/bin/gitopenbranch @@ -17,7 +17,8 @@ esac # Check if inside a git repository if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then current_branch=$(git rev-parse --abbrev-ref HEAD) - gh repo view --branch "$current_branch" --web || $open_cmd "$(gh repo view --branch "$current_branch" --json url -q '.url')" + # Open in browser, suppressing all output + nohup gh repo view --branch "$current_branch" --web >/dev/null 2>&1 & else echo "Not a git repository." exit 1 diff --git a/ar/.local/bin/rbackup b/ar/.local/bin/rbackup index 70c15d9..7ae89e5 100755 --- a/ar/.local/bin/rbackup +++ b/ar/.local/bin/rbackup @@ -90,7 +90,7 @@ sync_server() { ssh "$THESIAH_SERVER" "mkdir -p /root/.config/bash /root/.config/shell /root/.config/vim /root/.local/bin /root/.local/share /root/.local/state /var/www/thesiah" # Sync operations with explicit error checking - cd "$THESIAH_WWW" || exit 1 + cd "$THESIAH_WWW" || return 1 [ -d "$thesiah_path" ] || hugo --cleanDestinationDir rsync -vrazPlu --delete "$thesiah_path/" "$THESIAH_SERVER:/var/www/thesiah/" >/dev/null 2>&1 && rm -rf "$thesiah_path" rsync -vrazPlu --delete "$vim_path/vimrc" "$THESIAH_SERVER:/root/.config/vim/" >/dev/null 2>&1 @@ -121,10 +121,10 @@ sync_server() { } sync_nextcloud() { - base="$(basename $backup_path)" - parent="$(dirname $backup_path)" + base="$(basename "$backup_path")" + parent="$(dirname "$backup_path")" tmpdir="$(mktemp -d)" - cd "$tmpdir" || exit + cd "$tmpdir" || return 1 tar -C "$parent" -zcf "$base".tar.gz "$base" >/dev/null 2>&1 rsync -vrazPlu --delete "$tmpdir/$base".tar.gz "$THESIAH_SERVER:/var/www/nextcloud/data/si@thesiah.xyz/files/backup/" >/dev/null 2>&1 ssh "$THESIAH_SERVER" "chown -R www-data:www-data /var/www/nextcloud/data/si@thesiah.xyz/files/backup" >/dev/null 2>&1 @@ -178,10 +178,42 @@ echo "Backup starts to $backup_path..." process_options "$@" # Main script logic -#mount_luks && echo "Mount backup drive... " && echo "Success to mount luks drive!" || error "Failed to mount $backup_path" -[ -d "$backup_path" ] || sudo mkdir -p "$backup_path" -echo "Sync home files..." && sync_files && echo "Success to sync files!" || error "Failed back up files" -echo "Sync root files..." && sync_root && echo "Success to sync root!" || error "Failed back up root" -echo "Sync server files..." && sync_server && echo "Success to sync server!" || error "Failed back up server" -#echo "Sync files to nextcloud..." && sync_nextcloud && echo "Success to sync nextcloud!" || error "Failed back up nextcloud" +# Check if backup drive is available +backup_available=false +if mount | grep -q " /mnt/second "; then + backup_available=true + echo "Backup drive is mounted" +else + echo "Warning: /mnt/second is not mounted" + echo "Attempting to mount backup drive..." + if mount_luks 2>/dev/null && mountpoint -q /mnt/second 2>/dev/null; then + backup_available=true + echo "Success to mount luks drive!" + else + echo "Backup drive not available. Skipping file backup..." + fi +fi + +# Sync home files only if backup drive is available +if [ "$backup_available" = true ]; then + [ -d "$backup_path" ] || sudo mkdir -p "$backup_path" + echo "Sync home files..." && sync_files && echo "Success to sync files!" || echo "Warning: Failed to sync some files" +else + echo "Skipping home files sync (no backup drive)" +fi + +echo "Sync root files..." && sync_root && echo "Success to sync root!" || echo "Warning: Failed to sync root" + +# Sync server files only if server is configured +if [ -n "$THESIAH_SERVER" ]; then + echo "Sync server files..." && sync_server && echo "Success to sync server!" || echo "Warning: Failed to sync server" +else + echo "Skipping server sync (THESIAH_SERVER not set)" +fi + +# Sync to nextcloud only if backup drive is available and server is configured +if [ "$backup_available" = true ] && [ -n "$THESIAH_SERVER" ]; then + echo "Sync files to nextcloud..." && sync_nextcloud && echo "Success to sync nextcloud!" || echo "Warning: Failed to sync nextcloud" +fi + echo "Done!" diff --git a/ar/.local/bin/shortcuts b/ar/.local/bin/shortcuts index e131ce4..2f4c432 100755 --- a/ar/.local/bin/shortcuts +++ b/ar/.local/bin/shortcuts @@ -91,3 +91,30 @@ if [ -f "$yazi_shortcuts_tmp" ]; then mv "$yazi_shortcuts.new" "$yazi_shortcuts" rm -f "$yazi_shortcuts_tmp" fi + +# root +root_shell_shortcuts="/root/.config/shell/rootshortcutrc" +root_zsh_named_dirs="/root/.config/shell/rootzshnameddirrc" +root_lf_shortcuts="/root/.config/lf/rootshortcutrc" +root_vim_shortcuts="/root/.config/vim/rootshortcuts.vim" + +sudo rm -f "$root_zsh_named_dirs" "$root_lf_shortcuts" "$root_vim_shortcuts" 2>/dev/null +printf "# vim: filetype=sh\\nalias " | sudo tee "$root_shell_shortcuts" 2>/dev/null +sudo mkdir -p /root/.config/shell/ /root/.config/lf/ /root/.config/vim/ +sudo touch "$root_shell_shortcuts" "$root_zsh_named_dirs" "$root_lf_shortcuts" "$root_vim_shortcuts" + +eval "echo \"$(cat "$bmdirs")\"" | + sudo awk "!/^\s*#/ && !/^\s*\$/ && /cache|config($|\/bash|\/lf|\/shell|\/vim)|local\/(bin|share|state)$/ {gsub(\"\\\s*#.*$\",\"\"); gsub(\"home/$USER\", \"root\"); + printf(\",%s=\42cd %s && ls -A\42 \\\\\n\",\$1,\$2) >> \"$root_shell_shortcuts\" ; + printf(\"hash -d ,%s=%s \n\",\$1,\$2) >> \"$root_zsh_named_dirs\" ; + printf(\"map ,%s cd \42%s\42 \n\",\$1,\$2) >> \"$root_lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$root_vim_shortcuts\" ; + printf(\"nmap <localleader><localleader>%s :Explore %s<cr>\n\",\$1,\$2) >> \"$root_vim_shortcuts\"}" + +eval "echo \"$(cat "$bmfiles")\"" | + sudo awk "!/^\s*#/ && !/^\s*\$/ && /config\/(bash|lf|vim)\/.*rc |inputrc|\$EDITOR / {gsub(\"\\\s*#.*$\",\"\"); gsub(\"home/$USER\", \"root\"); + printf(\",%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$root_shell_shortcuts\" ; + printf(\"hash -d ,%s=%s \n\",\$1,\$2) >> \"$root_zsh_named_dirs\" ; + printf(\"map ,%s \$\$EDITOR \42%s\42 \n\",\$1,\$2) >> \"$root_lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$root_vim_shortcuts\" ; + printf(\"nmap <localleader><localleader>%s :e %s<cr>\n\",\$1,\$2) >> \"$root_vim_shortcuts\"}" diff --git a/ar/.local/bin/statusbar/sb-repos b/ar/.local/bin/statusbar/sb-repos index 001ca89..d5d5dc3 100755 --- a/ar/.local/bin/statusbar/sb-repos +++ b/ar/.local/bin/statusbar/sb-repos @@ -25,9 +25,12 @@ get_git_status_symbols() { } } END { - for (change in changes) { - printf "%s%s", change, changes[change] - } + # Print in consistent order: M, A, D, R, ? + if (changes["M"] > 0) printf "M%s", changes["M"] + if (changes["A"] > 0) printf "A%s", changes["A"] + if (changes["D"] > 0) printf "D%s", changes["D"] + if (changes["R"] > 0) printf "R%s", changes["R"] + if (changes["?"] > 0) printf "?%s", changes["?"] }' } @@ -41,7 +44,7 @@ get_unpulled_commits() { git rev-list --count HEAD..@{upstream}; } check_multi_repo_status() { local dir="$1" local icon="$2" - local status="" + local repo_status="" local changed_repos="" while IFS= read -r git_dir; do @@ -53,15 +56,15 @@ check_multi_repo_status() { unpulled=$(get_unpulled_commits) if [ -n "$changes" ] || [ "$unpushed" -gt 0 ] || [ "$unpulled" -gt 0 ]; then - status+="$icon$changes" - [ "$unpushed" -gt 0 ] && status+="↑$unpushed" - [ "$unpulled" -gt 0 ] && status+="↓$unpulled" - status+=" " + [ -n "$repo_status" ] && repo_status+=" " + repo_status+="$icon$changes" + [ "$unpushed" -gt 0 ] && repo_status+="↑$unpushed" + [ "$unpulled" -gt 0 ] && repo_status+="↓$unpulled" changed_repos+="$repo_dir"$'\n' fi done < <(find "$dir" -mindepth 2 -maxdepth 2 -type d -name ".git" 2>/dev/null) - printf "%s %s" "$status" "$changed_repos" + printf "%s|%s" "$repo_status" "$changed_repos" } # Function to check Git repository status for a single repository @@ -82,26 +85,29 @@ check_single_repo_status() { repo_status+="$icon$changes" [ "$unpushed" -gt 0 ] && repo_status+="↑$unpushed" [ "$unpulled" -gt 0 ] && repo_status+="↓$unpulled" - repo_status+=" " changed_repo="$dir" fi fi - printf "%s%s" "$repo_status" "$changed_repo" + printf "%s|%s" "$repo_status" "$changed_repo" } # Check statuses for repositories -dotfiles_status=$(check_single_repo_status "$dotfiles_repos" "$dotfiles_icon" | awk -F' ' '{print $1}') -dotfiles_changes=$(check_single_repo_status "$dotfiles_repos" "$dotfiles_icon" | awk -F' ' '{print $2}') +dotfiles_result=$(check_single_repo_status "$dotfiles_repos" "$dotfiles_icon") +dotfiles_status="${dotfiles_result%%|*}" +dotfiles_changes="${dotfiles_result#*|}" -suckless_status=$(check_single_repo_status "$suckless_repos" "$suckless_icon" | awk -F' ' '{print $1}') -suckless_changes=$(check_single_repo_status "$suckless_repos" "$suckless_icon" | awk -F' ' '{print $2}') +suckless_result=$(check_single_repo_status "$suckless_repos" "$suckless_icon") +suckless_status="${suckless_result%%|*}" +suckless_changes="${suckless_result#*|}" -private_status=$(check_multi_repo_status "$private_repos" "$private_icon" | awk -F' ' '{print $1}') -private_changes=$(check_multi_repo_status "$private_repos" "$private_icon" | awk -F' ' '{print $2}') +private_result=$(check_multi_repo_status "$private_repos" "$private_icon") +private_status="${private_result%%|*}" +private_changes="${private_result#*|}" -public_status=$(check_multi_repo_status "$public_repos" "$public_icon" | awk -F' ' '{print $1}') -public_changes=$(check_multi_repo_status "$public_repos" "$public_icon" | awk -F' ' '{print $2}') +public_result=$(check_multi_repo_status "$public_repos" "$public_icon") +public_status="${public_result%%|*}" +public_changes="${public_result#*|}" [ -f /tmp/gitsync ] && rm -f /tmp/gitsync @@ -113,7 +119,7 @@ output="" [ -n "$public_status" ] && output+="$public_status " # Trim trailing spaces and display output -output="${output%"${output##*[! ]}"}" +output="${output% }" [ -n "$output" ] && (cat /tmp/gitsync 2>/dev/null || echo "$output") openrepos() { @@ -121,7 +127,14 @@ openrepos() { repos_cleaned="$(echo "$all_changed_repos" | grep -v '^$')" if [ -n "$repos_cleaned" ]; then - setsid -f "$TERMINAL" -e opensessions $repos_cleaned >/dev/null 2>&1 + # Build array of repos + repos_array=() + while IFS= read -r repo; do + [ -n "$repo" ] && repos_array+=("$repo") + done <<< "$repos_cleaned" + + # Call opensessions with all repos as separate arguments + [ "${#repos_array[@]}" -gt 0 ] && setsid -f "$TERMINAL" -e opensessions "${repos_array[@]}" >/dev/null 2>&1 fi } |
