Revise rofi config with additional scripts

This commit is contained in:
foo-dogsquared 2020-06-06 22:56:07 +08:00
parent cf099de43c
commit 3fb84861ad
6 changed files with 138 additions and 4 deletions

21
rofi/mode/delim Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
if [ x"$@" = x"quit" ]
then
exit 0
fi
# Override the previously set prompt.
# We only want to do this on first call of script.
if [ $ROFI_RETV = 0 ]
then
echo -en "\x00delim\x1f|\n"
fi
echo -en "\x00prompt\x1fChange prompt|"
for a in {1..10}
do
echo -en "$a|"
done
echo -en "newline\ntest|"
echo -en "quit"

90
rofi/mode/recoll Executable file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env bash
# This is a Rofi script-mode script creating an interface for Recoll (https://www.lesbonscomptes.com/recoll/).
# The selected path is then opened with its desktop launcher (e.g., xdg-open) and its location is copied on the clipboard.
#
# Dependencies:
# * GNU Bash v5.0.13
# * Recoll v1.27.0 with Xapian v1.4.15
# * Dunst v1.4.1 with libnotify v0.7.9
# * A desktop launcher (like xdg-open).
# * A clipboard manager (like xclip).
# For getting started, you can view the documentation in https://github.com/davatorium/rofi/blob/next/doc/rofi-script.5.markdown.
# As of 2020-06-06, the official version is not yet release and this script is developed for the 'next' branch which may have bugs present.
# Exit immediately if it's not run as a Rofi script.
if [ -z "$ROFI_OUTSIDE" ]
then
echo "This script is not being run as a Rofi script."
echo "Usage: 'rofi -show <MODENAME> -modi <MODENAME>:$0"
exit 1
fi
# Do stuff on first boot.
if [ "$ROFI_RETV" = 0 ]
then
# Set the delimiter to '\x1'.
# This is useful for creating entries with newlines (though, you have to manually set '-eh' option with >1).
echo -en "\x00delim\x1f\\x1\n"
message="Search something..."
fi
# Some constants to be used.
# Btw, don't use primary selection of the location for copying it from xclip, it will freeze Rofi (and may cause this script to be empty which I found out the hard way).
open_launcher_cmd="xdg-open"
copy_to_clipboard_cmd="xclip -selection clipboard"
prompt="Recoll"
function show_help() {
echo -en "To search files, simply prepend the query with '##'.\x1"
echo -en "Anything else should get you back reading this help section.\x1"
echo -en "Happy searching, boisengirls! :)\x1"
}
# By the time the user provided an input, this conditional will always fail.
if [ -z "$@" ]
then
show_help
else
# If the entry is detected with the 'file://' URI protocol (which is returned from the Recoll query), it will open it and exit the script.
if [[ "$@" == file://* ]]
then
coproc ( "$open_launcher_cmd" "$@" > /dev/null 2>&1 ) && notify-send "Opening file at $@..."
exec 1>&-
exit
# If the argument is detected as a query string (which is in format '##<QUERY>'), it will run the Recoll query.
elif [[ "$@" == \#\#* ]]
then
recoll_query=${@#\#\#}
# The duration is in units of miliseconds.
# This is a crude way but it is the simplest solution I could easily fit for now.
duration_start=$(date +%s%N)
readarray -d '\n' search_result <<< $(recoll -b -t -q "$recoll_query" 2>/dev/null)
# Since the Recoll command-line interface doesn't have indications whether the query has successfully delivered at least one item or not, counting the length of the resulting string is the next best thing.
# If the string is only composed of one character, it most likely contain only a newline or something.
if [ "${#search_result}" -gt 1 ]
then
# We're reducing it by one since there's a newline in the beginning in the result.
query_count=$(echo "$search_result" | wc -l)
awk '{print $0}' <<< "$search_result" | xargs -I% echo -en "%\x1"
duration_end=$((($(date +%s%N) - $duration_start)/1000000))
message="You've searched '$recoll_query' with ($query_count - 1) results completed in $duration_end ms."
else
message="Lol, no results."
echo -en "I use Rofi btw.\x1"
fi
# Otherwise, all entries that lead to nothing simply go back to the help section as promised. >:)
else
show_help
fi
fi
# Display the current message and the prompt, whatever that is.
echo -en "\x00prompt\x1f$prompt\x1"
echo -en "\x00message\x1f$message\x1"

24
rofi/mode/script Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
if [ -z "${ROFI_OUTSIDE}" ]
then
echo "run this script in rofi".
exit
fi
if [ "$ROFI_RETV" = 1 ]
then
ROFI_RETV=11
fi
echo -en "\x00no-custom\x1ftrue\n"
echo -en "aap\0icon\x1ffolder\x1finfo\x1ftest\n"
echo -en "baa\x00info\x1fMONMON\n"
echo -en "aap\x00info\x1fWHAT\n"
if [ -n "${ROFI_INFO}" ]
then
echo "my info: ${ROFI_INFO} "
fi
notify-send "$ROFI_RETV"

View File

@ -29,7 +29,6 @@
background-color: @background;
font: "Font Awesome 5 Free,Font Awesome 5 Free Solid:style=Solid 14";
font: "Iosevka 14";
}
window {
@ -46,12 +45,13 @@ mainbox {
background-color: @background;
border: 2;
border-color: @color6;
children: [ inputbar, listview, mode-switcher ];
children: [ inputbar, message, listview, mode-switcher ];
padding: 0.5em;
}
inputbar,
listview {
listview,
message {
background: @background;
margin: 0 0 0.5em 0;
}
@ -97,7 +97,6 @@ listview {
}
element, button {
border-radius: 30%;
}
button,