sofi improvements

This commit is contained in:
Sage Vaillancourt 2023-12-13 12:24:21 -05:00
parent 2d4e7178da
commit 2ec5a54671
3 changed files with 169 additions and 15 deletions

View File

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="96e6e82b-0552-4d26-b2e7-ad0b56757840" />
</component>
</module> </module>

58
fake_home/.sofi-preview.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
choice="$1"
query_string="$2"
arg="$(echo "$choice" | cut -c 5-)"
arg="${arg/#\~/$HOME}"
case $choice in
git*)
tree -L 1 $arg
exit 0
;;
win*)
echo $choice
exit 0
;;
app*)
echo $choice
exit 0
;;
emj*)
echo $choice
exit 0
;;
fil*)
echo $choice
exit 0
;;
mvr*)
groupId="$(echo "$arg" | sed 's/\(.*\):.*/\1/')"
artifactId="$(echo "$arg" | sed 's/.*:\(.*\) .*/\1/')"
latestVersion="$(echo "$arg" | sed 's/.* \(.*\)/\1/')"
echo "<dependency>"
echo " <groupId>$groupId</groupId>"
echo " <artifactId>$artifactId</artifactId>"
echo " <version>$latestVersion</version>"
echo "</dependency>"
exit 0
;;
*)
qarg="$(echo "$query_string" | cut -c 5-)"
qarg="${qarg/#\~/$HOME}"
case $query_string in
mvn*)
curl -s "https://search.maven.org/solrsearch/select?q=$qarg&rows=5&wt=json" | jq '[.response.docs[] | { g, a, latestVersion, timestamp } ]' 2>/dev/null
;;
npm*)
NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
npm search $qarg | tail -n +2
;;
esac
;;
esac

View File

@ -10,13 +10,28 @@ FILE_LOCATIONS="$HOME/Documents $HOME/Downloads"
! [[ "$XDG_SESSION_TYPE" = "x11" ]] ! [[ "$XDG_SESSION_TYPE" = "x11" ]]
IS_X11="$?" IS_X11="$?"
sofi_id() {
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | cut -c 3- | rev | cut -c4- | rev | jq '.[] | .id' | while read id; do
if gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.GetTitle $id | grep "SOFI" &> /dev/null; then
echo $id
fi
done
}
# Open search window or raise existing one # Open search window or raise existing one
if [[ "$1" == "--launch" ]]; then if [[ "$1" == "--launch" ]]; then
if (($IS_X11)) && existing="$(xdotool search $WINDOW_NAME)"; then if (($IS_X11)) && existing="$(xdotool search $WINDOW_NAME)"; then
xdotool windowraise "$existing" xdotool windowraise "$existing"
else else
# xfce4-terminal --role="$WINDOW_NAME" --title="$WINDOW_NAME" --startup-id="$WINDOW_NAME" -e "bash -c '$HOME/.sofi.sh'" # xfce4-terminal --role="$WINDOW_NAME" --title="$WINDOW_NAME" --startup-id="$WINDOW_NAME" -e "bash -c '$HOME/.sofi.sh'"
xterm -fa 'Monospaced' -fs 10 -e "bash -c '$HOME/.sofi.sh'"
id="$(sofi_id)"
if [[ "$id" != "" ]]; then
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Activate $id
else
xterm -geometry 120x40 -fa 'Monospaced' -fs 10 -T "SOFI" -e "bash -c '$HOME/.sofi.sh'"
fi
# st -e bash -c '$HOME/.sofi.sh'" # st -e bash -c '$HOME/.sofi.sh'"
fi fi
exit $? exit $?
@ -24,14 +39,17 @@ fi
windows() { windows() {
if ! (($IS_X11)); then if ! (($IS_X11)); then
return gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | cut -c 3- | rev | cut -c4- | rev | jq '.[] | .id' | while read id; do
echo "win" "$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.GetTitle $id | cut -c 3- | rev | cut -c4- | rev)" "|" $id
done
else
xprop -root _NET_CLIENT_LIST |
pcregrep -o1 '# (.*)' |
sed 's/, /\n/g' |
xargs -I {} -n1 xprop -id {} _NET_WM_NAME |
grep -v '"Desktop"\|"xfce4-panel"' |
sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//'
fi fi
xprop -root _NET_CLIENT_LIST |
pcregrep -o1 '# (.*)' |
sed 's/, /\n/g' |
xargs -I {} -n1 xprop -id {} _NET_WM_NAME |
grep -v '"Desktop"\|"xfce4-panel"' |
sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//'
} }
read_apps() { read_apps() {
@ -42,6 +60,10 @@ read_apps() {
sed 's/Name=/app /' > "$CACHE_FILE" & sed 's/Name=/app /' > "$CACHE_FILE" &
} }
read_snap_apps() {
snap list | tail -n +2 | awk '{print "snp " $1}'
}
open_app() { open_app() {
app="$(echo "$1" | cut -c 5-)" app="$(echo "$1" | cut -c 5-)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -69,6 +91,7 @@ if [[ "$1" == "--print-only" ]]; then
<(windows) \ <(windows) \
<($HOME/.rofi-list-git-repos.py --no-icon) \ <($HOME/.rofi-list-git-repos.py --no-icon) \
<(read_apps) \ <(read_apps) \
<(read_snap_apps) \
<(list_files) \ <(list_files) \
$HOME/.emojis $HOME/.emojis
exit 1 exit 1
@ -78,28 +101,97 @@ choice="$(cat \
<(windows) \ <(windows) \
<("$HOME/.rofi-list-git-repos.py") \ <("$HOME/.rofi-list-git-repos.py") \
<(read_apps) \ <(read_apps) \
<(read_snap_apps) \
<(list_files) \ <(list_files) \
"$HOME/.emojis" \ "$HOME/.emojis" \
| fzf)" | fzf --print-query --preview="$HOME/.sofi-preview.sh {} {q}")"
echo
qstring="$(echo "$choice" | head -n 1)"
choice="$(echo "$choice" | tail -n 1)"
mvn_handler() {
qarg="$(echo "$1" | cut -c 5-)"
row_count=10
arr_result="$(curl -s "https://search.maven.org/solrsearch/select?q=$qarg&rows=$row_count&wt=json" | jq '[.response.docs[] | { g, a, latestVersion } ]')"
for i in 0 1 2 3 4 5 6 7 8 9; do
groupId="$(echo -n "$arr_result" | jq -r ".[$i].g")"
artifactId="$(echo -n "$arr_result" | jq -r ".[$i].a")"
latestVersion="$(echo -n "$arr_result" | jq -r ".[$i].latestVersion")"
echo "mvr $groupId:$artifactId $latestVersion"
done | fzf --print-query --preview="$HOME/.sofi-preview.sh {} {q}"
}
npm_handler() {
qarg="$(echo "$1" | cut -c 5-)"
NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
package="$(npm search $qarg | tail -n +2 | fzf | sed 's/ .*//')"
setsid xdg-open "https://npmjs.com/package/$package" &> /dev/null &
}
case $choice in case $choice in
git*) git*)
setsid "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null & setsid "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null &
;; ;;
win*) win*)
wmctrl -i -R "$(xwininfo -root -tree | if (($IS_X11)); then
grep "$(echo "$choice" | cut -c 5-)" | wmctrl -i -R "$(xwininfo -root -tree |
awk '{ print $1 }' | grep "$(echo "$choice" | cut -c 5-)" |
sed 's/0x/0x00/')" awk '{ print $1 }' |
sed 's/0x/0x00/')"
else
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Activate "$(echo "$choice" | sed 's/.* \([0-9]\+\)$/\1/')"
fi
;; ;;
app*) app*)
open_app "$choice" open_app "$choice"
;; ;;
snp*)
app="$(echo "$choice" | cut -c 5-)"
setsid $app >/dev/null 2>&1 </dev/null &
;;
emj*) emj*)
paste_emoji "$choice" paste_emoji "$choice"
;; ;;
fil*) fil*)
setsid xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null & setsid xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null &
;; ;;
*)
case $qstring in
mvn*)
lib="$(mvn_handler "$qstring")"
lib="$(echo "$lib" | cut -c 5-)"
groupId="$(echo -n "${lib//[$'\t\r\n']}" | sed 's/\(.*\):.*/\1/')"
artifactId="$(echo -n "${lib//[$'\t\r\n']}" | sed 's/.*:\(.*\) .*/\1/')"
latestVersion="$(echo -n "${lib//[$'\t\r\n']}" | sed 's/.* \(.*\)/\1/')"
xml="$(cat <<EOF
<dependency>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${latestVersion}</version>
</dependency>
EOF
)"
if (($IS_X11)); then
nohup xclip -selection clipboard <(echo -n "$xml") &> /dev/null &
else
wl-copy "$xml"
fi
echo "Copied to clipboard!"
sleep 0.5
;;
npm*)
lib="$(npm_handler "$qstring")"
lib="$(echo "$lib" | cut -c 5-)"
;;
esac
;;
esac esac
sleep 0.1 sleep 0.1