penguin/utils

my env utils

commit 27bece246e47937aa912e1411491867078990aa5

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-07-20T13:09:27Z
subjectAlias sshc to ssh for 42_clipboard_server
commit 27bece246e47937aa912e1411491867078990aa5
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-07-20T13:09:27Z

    Alias sshc to ssh for 42_clipboard_server
---
 bash/core/20_io.bash             | 45 ++++++++++++++++++++++++++++------
 bash/core/40_sources.bash        |  5 ++++
 bash/dist/rbashrc                | 52 +++++++++++++++++++++++++++++++++-------
 bash/dist/rbashrc.asc            | 10 ++++----
 bash/dist/sources.list           |  2 +-
 bash/sources/42_clipboard_server | 10 ++++----
 6 files changed, 99 insertions(+), 25 deletions(-)

diff --git a/bash/core/20_io.bash b/bash/core/20_io.bash
index 3d00abc..84e1d19 100755
--- a/bash/core/20_io.bash
+++ b/bash/core/20_io.bash
@@ -46,9 +46,31 @@ function rbash_download_sig {
 }
 
 rbash_cache() {
-	local sig="$1"
-	local url="$2"
-	local key file
+	local force_redownload=0
+	local sig url name key file
+
+	OPTIND=1
+	while getopts ":r" opt; do
+		case "$opt" in
+			r)
+				force_redownload=1
+				;;
+			\?)
+				echo "usage: rbash_cache [-r] SIG URL [NAME]" >&2
+				return 2
+				;;
+		esac
+	done
+	shift $((OPTIND - 1))
+
+	if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
+		echo "usage: rbash_cache [-r] SIG URL [NAME]" >&2
+		return 2
+	fi
+
+	sig="$1"
+	url="$2"
+	name="${3:-}"
 
 	if [ -z "${RBASH_CACHE_DIR:-}" ]; then
 		echo "rbash: RBASH_CACHE_DIR is not set" >&2
@@ -60,13 +82,21 @@ rbash_cache() {
 		return 1
 	}
 
-	if command -v md5sum >/dev/null 2>&1; then
-		key="$(printf '%s' "$url" | md5sum | cut -d' ' -f1)"
+	if [ -n "$name" ]; then
+		file="$RBASH_CACHE_DIR/$name"
 	else
-		key="$(printf '%s' "$url" | md5 | cut -d' ' -f1)"
+		if command -v md5sum >/dev/null 2>&1; then
+			key="$(printf '%s' "$url" | md5sum | cut -d' ' -f1)"
+		else
+			key="$(printf '%s' "$url" | md5 | cut -d' ' -f1)"
+		fi
+
+		file="$RBASH_CACHE_DIR/$key"
 	fi
 
-	file="$RBASH_CACHE_DIR/$key"
+	if [ "$force_redownload" -eq 1 ]; then
+		rm -f "$file"
+	fi
 
 	if [ ! -f "$file" ]; then
 		rbash_download_sig "$sig" "$url" "$file" || {
@@ -75,6 +105,7 @@ rbash_cache() {
 			echo "rbash: download failed: $url" >&2
 			return "$rc"
 		}
+
 		chmod 700 "$file"
 	fi
 
diff --git a/bash/core/40_sources.bash b/bash/core/40_sources.bash
index 03585b2..e8d2f60 100755
--- a/bash/core/40_sources.bash
+++ b/bash/core/40_sources.bash
@@ -48,6 +48,11 @@ rbash-list() {
 }
 
 r2ensource() {
+
+	if [ "$1" = "-f" ]; then
+		sources_list=$(rbash_cache -r "$RBASH_SOURCES_SUM" "$(rbash_sources_list)" "sources.list")
+	fi
+
 	rbash-list || return 1
 
 	local ids id selected tmp
diff --git a/bash/dist/rbashrc b/bash/dist/rbashrc
index be686c0..9662b89 100755
--- a/bash/dist/rbashrc
+++ b/bash/dist/rbashrc
@@ -18,7 +18,7 @@ RBASH_CONFIG="$RBASH_HOME/config"
 RBASH_ENV="$RBASH_HOME/env"
 RBASH_MERGED="$RBASH_CACHE_DIR/merged"
 RBASH_BIN="$RBASH_HOME/bin"
-RBASH_SOURCES_SUM="d92990747fccac0f0dff1c9bbfddcb26d592514cbdb5667dd7d96a727eeb99ee"
+RBASH_SOURCES_SUM="508ba717f5f31796f03fd176ecb50432a2c3d236896cef066f2cc535369bbca9"
 
 
 # ---- rbash: bash/core/00_env.bash ----
@@ -149,9 +149,31 @@ function rbash_download_sig {
 }
 
 rbash_cache() {
-	local sig="$1"
-	local url="$2"
-	local key file
+	local force_redownload=0
+	local sig url name key file
+
+	OPTIND=1
+	while getopts ":r" opt; do
+		case "$opt" in
+			r)
+				force_redownload=1
+				;;
+			\?)
+				echo "usage: rbash_cache [-r] SIG URL [NAME]" >&2
+				return 2
+				;;
+		esac
+	done
+	shift $((OPTIND - 1))
+
+	if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
+		echo "usage: rbash_cache [-r] SIG URL [NAME]" >&2
+		return 2
+	fi
+
+	sig="$1"
+	url="$2"
+	name="${3:-}"
 
 	if [ -z "${RBASH_CACHE_DIR:-}" ]; then
 		echo "rbash: RBASH_CACHE_DIR is not set" >&2
@@ -163,13 +185,21 @@ rbash_cache() {
 		return 1
 	}
 
-	if command -v md5sum >/dev/null 2>&1; then
-		key="$(printf '%s' "$url" | md5sum | cut -d' ' -f1)"
+	if [ -n "$name" ]; then
+		file="$RBASH_CACHE_DIR/$name"
 	else
-		key="$(printf '%s' "$url" | md5 | cut -d' ' -f1)"
+		if command -v md5sum >/dev/null 2>&1; then
+			key="$(printf '%s' "$url" | md5sum | cut -d' ' -f1)"
+		else
+			key="$(printf '%s' "$url" | md5 | cut -d' ' -f1)"
+		fi
+
+		file="$RBASH_CACHE_DIR/$key"
 	fi
 
-	file="$RBASH_CACHE_DIR/$key"
+	if [ "$force_redownload" -eq 1 ]; then
+		rm -f "$file"
+	fi
 
 	if [ ! -f "$file" ]; then
 		rbash_download_sig "$sig" "$url" "$file" || {
@@ -178,6 +208,7 @@ rbash_cache() {
 			echo "rbash: download failed: $url" >&2
 			return "$rc"
 		}
+
 		chmod 700 "$file"
 	fi
 
@@ -338,6 +369,11 @@ rbash-list() {
 }
 
 r2ensource() {
+
+	if [ "$1" = "-f" ]; then
+		sources_list=$(rbash_cache -r "$RBASH_SOURCES_SUM" "$(rbash_sources_list)" "sources.list")
+	fi
+
 	rbash-list || return 1
 
 	local ids id selected tmp
diff --git a/bash/dist/rbashrc.asc b/bash/dist/rbashrc.asc
index 2bf3c29..2a6d8a9 100644
--- a/bash/dist/rbashrc.asc
+++ b/bash/dist/rbashrc.asc
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNATURE-----
 
-iJEEABYKADkWIQR8HpSNhBJUxWnt+97Vz1+xz60nwwUCal4UHRsUgAAAAAAEAA5t
-YW51MiwyLjUrMS4xMiwwLDMACgkQ1c9fsc+tJ8O4gQD+IQqcafpgcckOfljmR3lO
-xjLOAXsO5McFX6opCBSZgxkA/19heZtnLv3LfhUdzB2hImKf2YnPIOfvEWW5yWpz
-2k4A
-=VxQF
+iJEEABYKADkWIQR8HpSNhBJUxWnt+97Vz1+xz60nwwUCal4d5BsUgAAAAAAEAA5t
+YW51MiwyLjUrMS4xMiwwLDMACgkQ1c9fsc+tJ8Nd+gD+KJLL3HNcQnM+bcQZovsc
+7Rw8obzGQ37BloiFHmCoufQA/RJkP3WL2zbLlBPrjJcj2IZ/bXRgmQaWtsIddaFN
+HnEI
+=6dLh
 -----END PGP SIGNATURE-----
diff --git a/bash/dist/sources.list b/bash/dist/sources.list
index c5f9743..f48851c 100644
--- a/bash/dist/sources.list
+++ b/bash/dist/sources.list
@@ -13,5 +13,5 @@ b5a488efc0558e2b795a1558e2c91a8aeecc3fd441d437aff3a4749d5eb0bdfc  sources/23_win
 5dbc166ce1b051b54d244ef5dc6b52dfbff03965e9abb0ed891d441dffbf8a76  sources/31_git-utils
 c9c270376844e7c7e3c48b1e86c2ce3e7824dde64e8724c17c5fc95910abd11c  sources/40_go-command
 c0e8ef70466063907b5ed9e52c13532b0019b8cb5975d020899804549a76a37f  sources/41_pivot-command
-e2af033a486bde23c6ee0a1a161d1cc0f279026dde048af1baead4b1bacb661a  sources/42_clipboard_server
+986563f225092fbf3514e396f4d651beef63cf7690202f85e2c2c420f386bf54  sources/42_clipboard_server
 d02be2a68e8bd1f7e5adacbdd0bdc4f426aabfa1a57709270b673617db6c5352  sources/60_diagnostics
diff --git a/bash/sources/42_clipboard_server b/bash/sources/42_clipboard_server
index e9a57bf..b4574d1 100644
--- a/bash/sources/42_clipboard_server
+++ b/bash/sources/42_clipboard_server
@@ -1,5 +1,3 @@
-# macOS clipboard receiver for SSH reverse forwarding.
-
 SSH_CLIPBOARD_DIR="${SSH_CLIPBOARD_DIR:-$HOME/.cache}"
 SSH_CLIPBOARD_SOCKET="${SSH_CLIPBOARD_SOCKET:-$SSH_CLIPBOARD_DIR/ssh-clipboard.sock}"
 SSH_CLIPBOARD_PIDFILE="${SSH_CLIPBOARD_PIDFILE:-$SSH_CLIPBOARD_DIR/ssh-clipboard.pid}"
@@ -7,7 +5,7 @@ SSH_CLIPBOARD_LOG="${SSH_CLIPBOARD_LOG:-$SSH_CLIPBOARD_DIR/ssh-clipboard.log}"
 
 # This path is created on the remote host.
 # Override it when the remote username differs from the local username.
-SSH_CLIPBOARD_REMOTE_SOCKET="${SSH_CLIPBOARD_REMOTE_SOCKET:-/tmp/ssh-clipboard-client.sock}"
+SSH_CLIPBOARD_REMOTE_SOCKET="/tmp/ssh-clipboard-client.sock"
 
 function clipboard_server_running {
 	local pid
@@ -89,6 +87,8 @@ EOF
 function sshc {
 	init_clipboard_server || return
 
+	echo "-- ssh with clipboard server"
+
 	command ssh \
 		-o StreamLocalBindUnlink=yes \
 		-o ExitOnForwardFailure=yes \
@@ -96,4 +96,6 @@ function sshc {
 		"$@"
 }
 
-init_clipboard_server
+if init_clipboard_server; then
+	alias ssh='sshc'
+fi