~skiqqy/bin

bin/purr -rwxr-xr-x 1.0 KiB
c3280652Stephen Cochrane Added sandbox script 6 days ago
                                                                                
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
45
46
47
48
49
#!/bin/bash
# Auther: Skiqqy
# This is a simple script allowing for easy creation of simple files.

SCRIPT_PATH=$(dirname $0)
. "$SCRIPT_PATH/import/alert.sh" > /dev/null 2>&1
[ ! $(command -v error) ] && echo "[WARNING] Missing 'error.sh' import"

usage () {
	echo -e "purr [options]\n"
	echo "h: Shows this message."
	echo "a: Append Text to a file."
}

while getopts "ha:f:" opt
do
	case $opt in
		h)
			usage
			exit 0
			;;
		a)
			append=1
			file="$OPTARG"
			;;
		f)
			file="$OPTARG"
			;;
		*)
			error "Invalid arg, use -h to see how to use purr." 1
			;;
	esac
done

[ -z $file ] && file="$RANDOM.purr"
if [ -z $append ]
then
	echo $file
	printf -- "-%.0s" $(seq $(tput cols)) && echo
	$(exec cat > $file && echo "Finished writing to $file.")
	printf -- "-%.0s" $(seq $(tput cols))
else
	[ ! -f $file ] && warning "'$file' does not exist, creating."
	echo $file
	printf -- "-%.0s" $(seq $(tput cols)) && echo
	[ -f $file ] && cat $file
	$(exec cat >> $file && echo "Finished appending to $file.")
	printf -- "-%.0s" $(seq $(tput cols))
fi