-
-
Notifications
You must be signed in to change notification settings - Fork 95
How I am using bemenu with [ID] at line ends
GNU Support edited this page Mar 7, 2021
·
1 revision
In this script I am utilizing the psql
to get list items from the PostgreSQL database. List items are then listed as:
- Some choice [1]
- Some choice [2]
- Some choice [3]
and then I am using
string_cut_id() {
sed -n 's/\(.*\)\[\(.*\)\]$/\2/p'
}
to cut the ID from [ID]
at line ends. By using the ID I am then taking other information from the database. This may be useful for other users.
#!/bin/bash
# Because Bemenu is installed by using Guix, I have to remove $LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
export BEMENU_BACKEND=curses
fuzzy_program="bemenu -i"
if test $TERM = "dumb" && test $DISPLAY; then
BEMENU_BACKEND=x11;
# BEMENU_SCALE=1.4;
fuzzy_program='bemenu -i -b -l 10 -nb yellow -nb black --fn "DejaVu Mono 20"'
fi
#
rcd_sql() {
psql -AXtqc "$1"
}
string_cut_id() {
sed -n 's/\(.*\)\[\(.*\)\]$/\2/p'
}
fuzzy_id() {
$fuzzy_program | string_cut_id
}
rcd_accounts_list() {
rcd_sql "SELECT accounts_name || ' [' || accounts_id || ']' FROM accounts ORDER BY accounts_name"
}
rcd_account() {
id=$(rcd_accounts_list | fuzzy_id)
echo $id
}
hyperdocument_affiliate_list() {
rcd_sql "SELECT hlinks_name || ' [' || hlinks_id || ']' FROM hlinks WHERE hlinks_parent = 35720"
}
hyperdocument_affiliate() {
id=$(hyperdocument_affiliate_list | fuzzy_id)
rcd_sql "SELECT hlinks_name || '
' || hlinks_link FROM hlinks WHERE hlinks_id = `echo -n $id`"
}
hyperdocument_set_list() {
rcd_sql "SELECT hlinks_name || ' [' || hlinks_id || ']' FROM hlinks WHERE hlinks_hlinktypes = 5 ORDER BY hlinks_name"
}
hyperdocument_set() {
id=$(hyperdocument_set_list | fuzzy_id)
echo $id
}
arg=$1
case $arg in
'account') rcd_account ;;
'set') hyperdocument_set ;;
'affiliate' ) hyperdocument_affiliate ;;
*) echo "No recognized parameter"
exit 0 ;;
esac