-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.sh
More file actions
executable file
·44 lines (43 loc) · 1.57 KB
/
server.sh
File metadata and controls
executable file
·44 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
CONFIG_DIR="$HOME/.copy-cat-tail/config"
. "$CONFIG_DIR/config"
cd $WORKING_DIR
prevSelection=""
currentSelection=''
echo "server listening to copies texts"
while :
do
sleep 0.5
currentSelection=$(xclip -o -selection clipboard)
if [ "$currentSelection" != "$prevSelection" ];
then
files=$(find $WORKING_DIR/copies -maxdepth 1 -type f)
echo -n "$currentSelection" > "$WORKING_DIR/currentCopy.txt"
fileFound=$((-1))
numberOfFiles=0
for file in $files
do
difference=$(diff -s currentCopy.txt copies/clip$numberOfFiles.txt | grep "identical")
if [ "$difference" == "Files currentCopy.txt and copies/clip$numberOfFiles.txt are identical" ];
then
fileFound=$(($numberOfFiles % $MAX_COPY_LIMIT))
fi
numberOfFiles=$(($numberOfFiles + 1))
done
if [[ $fileFound -eq -1 ]]
then
currentWriteIdxFile=$(ls | grep "currentWriteIdx.txt")
currentWriteIdx=$(($numberOfFiles))
if [ "$currentWriteIdxFile" != "" ];
then
currentWriteIdx=$(cat currentWriteIdx.txt)
fi
echo -n "$currentSelection" > "$WORKING_DIR/copies/clip$currentWriteIdx.txt"
fileFound=$(($currentWriteIdx))
currentWriteIdx=$((($currentWriteIdx + 1) % $MAX_COPY_LIMIT))
echo -n $currentWriteIdx > "currentWriteIdx.txt"
fi
echo -n $fileFound > "$WORKING_DIR/currentIdx.txt"
fi
prevSelection=$currentSelection
done