Pass ln.

Hugo Hörnquist hugo at lysator.liu.se
Fri Jan 31 18:45:10 CET 2020


I wrote together a small patch for creating symlinks in the password
tree. Is this of interest?
-- 
hugo
-------------- next part --------------
>From 9d5b8b072e2d600249a531771d558db6fc359155 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo at hornquist.se>
Date: Mon, 23 Dec 2019 00:50:20 +0100
Subject: [PATCH] Add ln command.

---
 src/password-store.sh | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..f9d0d03 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -593,8 +593,8 @@ cmd_delete() {
 }
 
 cmd_copy_move() {
-	local opts move=1 force=0
-	[[ $1 == "copy" ]] && move=0
+	local opts force=0
+	action=$1
 	shift
 	opts="$($GETOPT -o f -l force -n "$PROGRAM" -- "$@")"
 	local err=$?
@@ -623,7 +623,8 @@ cmd_copy_move() {
 	[[ ! -t 0 || $force -eq 1 ]] && interactive="-f"
 
 	set_git "$new_path"
-	if [[ $move -eq 1 ]]; then
+	case $action in
+	move)
 		mv $interactive -v "$old_path" "$new_path" || exit 1
 		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
 
@@ -640,11 +641,18 @@ cmd_copy_move() {
 			[[ -n $(git -C "$INNER_GIT_DIR" status --porcelain "$old_path") ]] && git_commit "Remove ${1}."
 		fi
 		rmdir -p "$old_dir" 2>/dev/null
-	else
+		;;
+	copy)
 		cp $interactive -r -v "$old_path" "$new_path" || exit 1
 		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
 		git_add_file "$new_path" "Copy ${1} to ${2}."
-	fi
+		;;
+	link)
+		ln -s $interactive -r -v "$old_path" "$new_path" || exit 1
+		# [[ -e "$new_path" ]] && reencrypt_path "$new_path"
+		git_add_file "$new_path" "Symlink ${1} to ${2}."
+		;;
+	esac
 }
 
 cmd_git() {
@@ -713,6 +721,7 @@ case "$1" in
 	delete|rm|remove) shift;	cmd_delete "$@" ;;
 	rename|mv) shift;		cmd_copy_move "move" "$@" ;;
 	copy|cp) shift;			cmd_copy_move "copy" "$@" ;;
+	ln) shift;			cmd_copy_move "link" "$@" ;;
 	git) shift;			cmd_git "$@" ;;
 	*)				cmd_extension_or_show "$@" ;;
 esac
-- 
2.25.0



More information about the Password-Store mailing list