some minor fixes to sxp
This commit is contained in:
parent
9a85b4afe7
commit
d3f882de03
|
@ -2,8 +2,8 @@
|
||||||
# speedwm-sxp
|
# speedwm-sxp
|
||||||
|
|
||||||
# some functions we can use on demand
|
# some functions we can use on demand
|
||||||
print_text() { printf "%s\n%s\nClear\nRemove\nExit\n" "$(cat "$CUSTOM_HISTFILE")" "------"; } # function which returns history
|
print_text() { printf "%s\n%s\nClear\nRemove\nExit" "$(grep -ve '^$' $CUSTOM_HISTFILE)" "------"; } # function which returns history
|
||||||
print() { OP="$(print_text | "$RUNLAUNCHER" -g 1 -l 40 -p "$*")"; } # function which prints the menu
|
print_menu() { OP="$(print_text | "$RUNLAUNCHER" -g 1 -l 40 -p "$*")"; } # function which prints the menu
|
||||||
|
|
||||||
# basic variables
|
# basic variables
|
||||||
[ -z "$CUSTOM_HISTFILE" ] && CUSTOM_HISTFILE="$HOME/.config/speedwm/.custom_history"
|
[ -z "$CUSTOM_HISTFILE" ] && CUSTOM_HISTFILE="$HOME/.config/speedwm/.custom_history"
|
||||||
|
@ -14,26 +14,28 @@ mkdir -p "$(dirname "$CUSTOM_HISTFILE")"; touch "$CUSTOM_HISTFILE"
|
||||||
|
|
||||||
# parse current expression
|
# parse current expression
|
||||||
parse() {
|
parse() {
|
||||||
print "$@"
|
print_menu "$@"
|
||||||
[ "$OP" = "Clear" ] && printf "" > "$CUSTOM_HISTFILE" && exit
|
case "$OP" in
|
||||||
[ "$OP" = "Exit" ] && exit 0
|
"Clear") rm -f "$CUSTOM_HISTFILE"; mkdir -p "$(dirname "$CUSTOM_HISTFILE")"; touch "$CUSTOM_HISTFILE"; main "$@" ;;
|
||||||
[ "$OP" = "------" ] && exit 0
|
"Exit") exit 0 ;;
|
||||||
[ -z "$OP" ] && exit 0
|
"------") exit 0 ;;
|
||||||
|
"") exit 0 ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
parse "Enter an S expression:"
|
parse "Enter an S expression:"
|
||||||
[ "$OP" = "Remove" ] && \
|
[ "$OP" = "Remove" ] && \
|
||||||
remove_entry "$@" || \
|
remove_entry "$@" || \
|
||||||
add_entry "$@"
|
perf_entry "$@"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# write expression
|
# write expression
|
||||||
add_entry() {
|
perf_entry() {
|
||||||
FILE_CONTENTS="$(grep -v "$OP" "$CUSTOM_HISTFILE")"
|
file_contents="$(grep -v "$OP" "$CUSTOM_HISTFILE")"
|
||||||
printf "%s\n" "$FILE_CONTENTS" > "$CUSTOM_HISTFILE" # prevent duplicates
|
printf "%s\n" "$file_contents" > "$CUSTOM_HISTFILE" # prevent duplicates
|
||||||
|
|
||||||
# add entry
|
# add entry
|
||||||
printf "%s\n" "$OP" >> "$CUSTOM_HISTFILE"
|
printf "%s\n" "$OP" >> "$CUSTOM_HISTFILE"
|
||||||
|
@ -46,9 +48,9 @@ remove_entry() {
|
||||||
parse "Remove:"
|
parse "Remove:"
|
||||||
[ "$OP" = "Remove" ] && remove_entry "$@"
|
[ "$OP" = "Remove" ] && remove_entry "$@"
|
||||||
|
|
||||||
# add everything except the entry to $FILE_CONTENTS and write that back to the file
|
# add everything except the entry to $file_contents and write that back to the file
|
||||||
FILE_CONTENTS="$(grep -v "$OP" "$CUSTOM_HISTFILE")" || return 1
|
file_contents="$(grep -v "$OP" "$CUSTOM_HISTFILE")" || return 1
|
||||||
printf "%s\n" "$FILE_CONTENTS" > "$CUSTOM_HISTFILE" || return 1
|
printf "%s\n" "$file_contents" > "$CUSTOM_HISTFILE" || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in a new issue