scripts reorganize
This commit is contained in:
1 parent
a2a056a68d
commit
0734bee219
60 files changed
+824
-5
No files matched your search
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
on_exit() {
|
||||
(ccrypt -K "$now" -d "$file.cpt")
|
||||
|
||||
# prepare regex pattern
|
||||
shopt -s extglob
|
||||
readarray -t removeArray < <(grep -ve '^$\|^#' "$file")
|
||||
IFS='|' eval 'PATTERN="(${removeArray[*]})"'
|
||||
PATTERN="(^|[^a-zA-Z])$PATTERN([^a-zA-Z]|$)"
|
||||
|
||||
case $shell in
|
||||
*fish)
|
||||
printf "sanitizing fish history!\n"
|
||||
"$(dirname "$0")/sanitize_hist.fish" "$PATTERN" "/home/$(whoami)/.local/share/fish/fish_history"
|
||||
;;
|
||||
*bash)
|
||||
printf "sanitizing bash history!\n"
|
||||
"$(dirname "$0")/sanitize.sh" "$PATTERN" "/home/$(whoami)/.bash_history" 1
|
||||
;;
|
||||
*)
|
||||
printf "autosanitize has no implementation for %s\n" "$shell"
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -r ~/.cache/thumbnails/*
|
||||
rm "$file"
|
||||
}
|
||||
|
||||
trap 'on_exit' EXIT
|
||||
now=$(date +%s.%N)
|
||||
folder=/run/media/$(whoami)/P/Scripts
|
||||
file=/tmp/tags
|
||||
shell=$(grep "$(whoami)" < /etc/passwd | awk -F':' '{print $NF}' )
|
||||
|
||||
echo "copying tags to temp file..."
|
||||
cat "$folder/tags2" "$folder/tags" > "$file"
|
||||
(sed -i '/^$/d;/^\#.*$/d' "$file")
|
||||
(ccrypt -K "$now" "$file")
|
||||
while :; do
|
||||
sleep 600
|
||||
done
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
#This script sanitizes a file in the following manner:
|
||||
#it reads a pattern and a destFile
|
||||
#then, all lines in destFILE that can be regexp'd to pattern are removed.
|
||||
#optionally, a confirm variable is also specified; if so, the script does not prompt the user before overwriting destFILE
|
||||
|
||||
#this script takes the following input:
|
||||
#sanitize.sh pattern destFile [confirm]
|
||||
|
||||
#make sure input is valid
|
||||
[[ "$1" == "" || "$2" == "" ]] && printf "Incorrect input format.\nUse: \t sanitize.sh pattern destFile [confirm]\n" && exit
|
||||
[[ ! -f "$2" ]] && printf 'destFile - %s - does not exist!\n' "$2" && exit
|
||||
|
||||
|
||||
PATTERN=$1
|
||||
destFile=$2
|
||||
saveArray=()
|
||||
discardArray=()
|
||||
[[ "$3" =~ [yY][eE][sS]|[yY]|1|[tT][rR][uU][eE] ]] && confirm=0 || confirm=1
|
||||
|
||||
#go through each line, adding to either SAVE or DISCARD as necessary
|
||||
while read -r line; do
|
||||
[[ ! $line =~ $PATTERN ]] && saveArray+=("$line") || discardArray+=("$line")
|
||||
done < "$destFile"
|
||||
|
||||
#confirm output
|
||||
if [[ $confirm -eq 1 ]]; then
|
||||
printf "Discarding the following:\n"
|
||||
printf '%s\n' "${discardArray[@]}"
|
||||
else
|
||||
printf 'Discarding %d line(s).\n' "${#discardArray[@]}"
|
||||
fi
|
||||
|
||||
#confirm the user is ok with this
|
||||
response="y"
|
||||
[[ $confirm -eq 1 ]] && read -r -p "Proceed? (y/N): " response
|
||||
if [[ "$response" =~ [yY][eE][sS]|[yY] ]]; then
|
||||
echo "Removing unwanted lines..."
|
||||
printf '%s\n' "${saveArray[@]}" > "$destFile"
|
||||
fi
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env fish
|
||||
|
||||
# This script filters a file on a given regex, deleting all entries that match.
|
||||
# it is intended to be used with yaml-like files (namely, the fish shell history file)
|
||||
# and will delete entries, not individual lines. To give an example:
|
||||
# - cmd: "cd ~/Documents"
|
||||
# when: 128301283
|
||||
# - paths:
|
||||
# /usr/bin
|
||||
# - cmd: "mv file file2"
|
||||
# when: 1928321
|
||||
# with the regex "(^|[^a-z])(Documents)($|[^a-z])" will result in:
|
||||
# - cmd: "mv file file2"
|
||||
# when: 1928321
|
||||
# (note how it deletes not only the line containing the matched regex, but also the 'when' and 'paths' components).
|
||||
#
|
||||
# the input for this script is:
|
||||
# script.fish Regex File
|
||||
# where:
|
||||
# Regex is the pattern to be matched, and
|
||||
# File is the file to be filtered.
|
||||
|
||||
# error handling
|
||||
if not test -f "$argv[2]"
|
||||
printf 'Wrong syntax!\nUse:\t%s\tRegex\tFile' "$(basename (status -f))"
|
||||
exit
|
||||
end
|
||||
|
||||
# setup
|
||||
set -f is_writing "false"
|
||||
set -f tempFile (mktemp -p '' fish_hist.XXXXX)
|
||||
set -f num_deleted 0
|
||||
|
||||
# loop through the file
|
||||
while read -lad ' ' line
|
||||
if string match -qri "^- cmd:" -- "$line"
|
||||
if string match -qri "$argv[1]" -- "$line"
|
||||
set is_writing "false"
|
||||
set num_deleted (math $num_deleted + 1)
|
||||
else
|
||||
printf '%s\n' "$line" >> "$tempFile"
|
||||
set is_writing "true"
|
||||
end
|
||||
else if string match -q "true" -- "$is_writing"
|
||||
printf '%s\n' "$line" >> "$tempFile"
|
||||
end
|
||||
end < "$argv[2]"
|
||||
|
||||
printf 'Discarding %d line(s).\n ' "$num_deleted"
|
||||
|
||||
# replace files
|
||||
rm "$argv[2]"
|
||||
cp "$tempFile" "$argv[2]"
|
||||