~skiqqy/q

0cd02f7988e5cbc7266af67d8d37628e3cd17f48 — Stephen Cochrane 1 year, 8 months ago 2d2950c
Changed delim field to \x1f
1 files changed, 16 insertions(+), 21 deletions(-)

M q
M q => q +16 -21
@@ 97,7 97,7 @@ qpeek()
# See: q help push
qpush()
{
	prio=${1:-$(tail -1 "$qdir/q" | cut -d: -f3)}
	prio=${1:-$(tail -1 "$qdir/q" | cut -d"$delim" -f3)}
	[ -z "$prio" ] && prio=0
	if [[ ! "$prio" =~ ^[0-9]+$ ]] || [[ ! "$prio" -ge 0 ]] > /dev/null
	then


@@ 108,15 108,15 @@ qpush()
	read -rp "Title: " title
	read -rp "Desc: "  desc

	if [ "$prio" = "$(tail -1 "$q" | cut -d: -f3)" ] # If max prio, simply put on top of stack.
	if [ "$prio" = "$(tail -1 "$q" | cut -d"$delim" -f3)" ] # If max prio, simply put on top of stack.
	then
		echo "$title:$id:$prio:$desc" >> "$q"
		echo "$title$delim$id$delim$prio$delim$desc" >> "$q"
		echo "$((++id))" > "$qdir/id"
		return
	fi

	t=0
	while IFS=':' read -r i i p i
	while IFS="$delim" read -r i i p i
	do
		if [ "$prio" -ge "$p" ]
		then


@@ 128,12 128,11 @@ qpush()

	l=$(($(wc -l "$q" | cut -d" " -f 1)-t)) # Calculate the amount of items below the item to be inserted.

	# Subshell go brrr
	(
	{
		head -"$t" "$q"
		echo "$title:$id:$prio:$desc"
		echo "$title$delim$id$delim$prio$delim$desc"
		tail -"$l" "$q"
	) > "$qdir/qt"
	} > "$qdir/qt"
	mv "$qdir/qt" "$q"

	echo "$((++id))" > "$qdir/id"


@@ 142,7 141,7 @@ qpush()
# See: q help ed
qed()
{
	line=$(grep -E ".*:$1:" "$q")
	line=$(grep -E ".*$delim$1$delim" "$q")

	if [ -z "$line" ]
	then


@@ 167,7 166,7 @@ qed()
		return 1
	fi
	
	sed -i "/.*:$1:.*/d" "$q" # TODO: maybe use ed to preserve symlinks
	sed -i "/.*$delim$1$delim.*/d" "$q" # TODO: maybe use ed to preserve symlinks
	id=$1 && printf '%s\n%s\n' "$title" "$desc" | qpush "$prio" # Update the stack
}



@@ 195,7 194,7 @@ qdmenu()
		select=$(dmenu -l "$(echo "$data" | wc -l | cut -d " " -f 1)" <<< "$data")
	do
		id=$(sed -E 's|ID(.*) ->.*|\1|g' <<< "$select")
		grep -E ".*:$id:" "$q" | cut -d: -f4 | dmenu -l 1
		grep -E ".*$delim$id$delim" "$q" | cut -d "$delim" -f4 | dmenu -l 1
	done
	return 0 # Force clean exit code.
}


@@ 215,22 214,17 @@ qclean()
# Read a string and split it into vars
parse()
{
	title=$(echo "$1" | cut -d: -f1)
	id=$(echo "$1" | cut -d: -f2)
	prio=$(echo "$1" | cut -d: -f3)
	desc=$(echo "$1" | cut -d: -f4)
	title=$(echo "$1" | cut -d "$delim" -f1)
	id=$(echo "$1"    | cut -d "$delim" -f2)
	prio=$(echo "$1"  | cut -d "$delim" -f3)
	desc=$(echo "$1"  | cut -d "$delim" -f4)
}

# Print an item from the stack nicely
unpack()
{
	parse "$1"
	cat << EOF
Title: $title
ID: $id
Priority: $prio
$desc
EOF
	printf 'Title: %s\nID: %s\nPriority: %s\n%b\n' "$title" "$id" "$prio" "$desc"
}

qhelp()


@@ 340,6 334,7 @@ main()
	nic=
	privkey=
	domain=
	delim="$(echo -e '\x1f')"

	while getopts "hd:q:" opt
	do