feat: Implement clipboard manager commands and history management

- Added command to clear clipboard history (`cmd_clear.go`).
- Implemented command to copy a history item back to the clipboard (`cmd_copy.go`).
- Created command to list clipboard history (`cmd_list.go`).
- Developed command to watch clipboard changes and store history (`cmd_watch.go`).
- Introduced configuration loading for logging and clipboard settings (`config.go`).
- Established main application logic with command registration and configuration handling (`main.go`).
- Implemented history management with loading, saving, and clearing functionality (`history.go`).
- Defined history item structure to store clipboard data (`history_item.go`).
- Added utility functions for hashing data and summarizing clipboard content (`hash.go`, `summary.go`).
- Updated dependencies in `go.sum`.
This commit is contained in:
2025-05-20 17:52:58 +02:00
commit 1dad8ca69b
22 changed files with 990 additions and 0 deletions

48
bin/scripts/build-binary.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
BINARY_NAME=$1
BINARY_PATH=$2
COMPLETION_SCRIPT=$3
BINARY_PATH_VERSION=$BINARY_PATH.version
source bin/helpers/func.sh
# Check if HEAD is clean, if not abort
if [ -n "$(git status --porcelain)" ]; then
printfe "%s\n" "yellow" "You have uncomitted and/or untracked changes in your working directory."
fi
# Get the current tag checked out to HEAD and hash
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null)
LATEST_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
LATEST_TAG_HASH=$(git rev-list -n 1 --abbrev-commit $LATEST_TAG 2>/dev/null)
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
# If BRANCH is HEAD and latest commit hash equals latest tag hash, we are on a tag and up to date
if [ "$BRANCH" == "HEAD" ] && [ "$LATEST_COMMIT_HASH" == "$LATEST_TAG_HASH" ]; then
BRANCH=$LATEST_TAG
fi
# In case the current head has uncomitted and/or untracked changes, append a postfix to the version saying (dirty)
if [ -n "$(git status --porcelain)" ]; then
POSTFIX=" (dirty)"
fi
printfe "%s\n" "cyan" "Building $BINARY_NAME binary for $BRANCH ($LATEST_COMMIT_HASH)$POSTFIX..."
go build -o $BINARY_PATH ./src
if [ $? -ne 0 ]; then
printf "\033[0;31m"
echo "Build failed."
printf "\033[0m"
exit 1
fi
# Put tag and hash in .kcm_version file
echo "$BRANCH ($LATEST_COMMIT_HASH)$POSTFIX" > $BINARY_PATH_VERSION
printfe "%s\n" "cyan" "Generating Bash completion script..."
$BINARY_PATH completion bash > $COMPLETION_SCRIPT
printfe "%s\n" "green" "Bash completion script installed to $COMPLETION_SCRIPT."
printfe "%s\n" "green" "Restart or 'source ~/.bashrc' to update your shell."

19
bin/scripts/clean.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
source bin/helpers/func.sh
# $1 should be binary path
BINARY_PATH=$1
# $2 should be completion script path
COMPLETION_SCRIPT=$2
# Confirm these are paths
if [ -z "$BINARY_PATH" ] || [ -z "$COMPLETION_SCRIPT" ]; then
printfe "%s\n" "red" "Usage: $0 <binary_path> <completion_script_path>"
exit 1
fi
printfe "%s\n" "cyan" "Cleaning up old binaries and completion scripts..."
rm -f $BINARY_PATH
rm -f $COMPLETION_SCRIPT

27
bin/scripts/install-global.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
source bin/helpers/func.sh
# Remove any existing kcm installation
if [ -f "/usr/local/bin/kcm" ]; then
printfe "%s\n" "yellow" "Removing existing kcm installation..."
rm /usr/local/bin/kcm
fi
if [ -f "/usr/share/bash-completion/completions/kcm" ]; then
printfe "%s\n" "yellow" "Removing existing kcm bash completion..."
rm /usr/share/bash-completion/completions/kcm
fi
# Copy binary files to /usr/local/bin
printfe "%s\n" "cyan" "Installing kcm..."
cp $(pwd)/bin/kcm /usr/local/bin/kcm
cp $(pwd)/bin/kcm-completion.bash /usr/share/bash-completion/completions/kcm
# In case /etc/kcm/config.yaml does not exist, create it
if [ ! -f "/etc/kcm/config.local.yaml" ]; then
printfe "%s\n" "cyan" "Creating default configuration file..."
mkdir -p /etc/kcm
cp $(pwd)/config/config.local.example.yaml /etc/kcm/config.local.yaml
fi
printfe "%s\n" "green" "Installation complete."

16
bin/scripts/install.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Create any missing directories/files
touch ~/.bash_completion
mkdir -p $HOME/.local/bin/
# Symbolically link binaries
ln -sf $(pwd)/bin/kcm $HOME/.local/bin/kcm
ln -sf $(pwd)/bin/kcm-completion.bash $HOME/.local/bin/kcm-completion.bash
# Add completion to bash_completion for kcm
sed -i '/kcm/d' ~/.bash_completion
echo "source $HOME/.local/bin/kcm-completion.bash" >> ~/.bash_completion
echo "Installation complete."
source ~/.bash_completion

29
bin/scripts/uninstall.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/usr/env bash
if [ -f $HOME/.local/bin/kcm ]; then
echo "Removing kcm from $HOME/.local/bin"
rm $HOME/.local/bin/kcm
rm $HOME/.local/bin/T
fi
if [ -f $HOME/.local/bin/kcm-completion.bash ]; then
echo "Removing kcm-completion.bash from $HOME/.local/bin"
rm $HOME/.local/bin/kcm-completion.bash
fi
if [ -f $HOME/.local/bin/php ]; then
echo "Removing php from $HOME/.local/bin"
rm $HOME/.local/bin/php
fi
if [ -f $HOME/.local/bin/composer ]; then
echo "Removing composer from $HOME/.local/bin"
rm $HOME/.local/bin/composer
fi
if [ -f $HOME/.local/bin/phpstan ]; then
echo "Removing phpstan from $HOME/.local/bin"
rm $HOME/.local/bin/phpstan
fi
echo "Uninstall complete."