Skip to content

Instantly share code, notes, and snippets.

@jimfrize
Created May 5, 2023 22:24
Show Gist options
  • Save jimfrize/3b414e3a5b90e76aebf7c7846ceed655 to your computer and use it in GitHub Desktop.
Save jimfrize/3b414e3a5b90e76aebf7c7846ceed655 to your computer and use it in GitHub Desktop.
fxl - Fuzzy search and xdg launcher tool (dependancies: fzf dex xclip xdg-utils)
#!/bin/bash
if [[ -z $EDITOR ]]
then
EDITOR=nano
fi
if [[ ! -f ~/.config/mimeapps.list ]]
then
sudo update-desktop-database -q
sudo cp /usr/share/applications/mimeinfo.cache ~/.config/mimeapps.list
fi
main_menu ()
{
tput clear
echo "_________-FXL-_________"
echo
echo "[1] Search files"
echo "[2] Search applications"
echo "[3] Edit defaults"
echo "[4] Quit"
echo
read -rsn1
if [[ $REPLY == 1 ]]
then
export FZF_DEFAULT_COMMAND="find ."
search_result=""
search_result=`fzf --preview="file -b {}" --preview-window=up:10%`
if [[ $search_result == "" ]]
then
main_menu
else
selection_menu
fi
elif [[ $REPLY == 2 ]]
then
export FZF_DEFAULT_COMMAND="find . -name *.desktop"
search_result=""
search_result=`fzf`
if [[ $search_result == "" ]]
then
main_menu
else
setsid dex $search_result >> /dev/null 2>&1
tput clear
fi
elif [[ $REPLY == 3 ]]
then
tput clear
sudo $EDITOR ~/.config/mimeapps.list
elif [[ $REPLY == 4 ]]
then
tput clear
else
main_menu
fi
}
selection_menu ()
{
tput clear
echo "_________-FXL-_________"
echo
echo "[1] Open with default"
echo "[2] Open in editor"
echo "[3] Sudo open in editor"
echo "[4] Run in terminal"
echo "[5] Sudo run in terminal"
echo "[6] Copy to clipboard"
echo "[7] Main menu"
echo "[8] Quit"
echo
read -rsn1
tput clear
if [[ $REPLY == 1 ]]
then
setsid xdg-open "$search_result" & pkill -n $!
elif [[ $REPLY == 2 ]]
then
$EDITOR "$search_result"
elif [[ $REPLY == 3 ]]
then
sudo $EDITOR "$search_result"
elif [[ $REPLY == 4 ]]
then
"$search_result"
elif [[ $REPLY == 5 ]]
then
sudo "$search_result"
elif [[ $REPLY == 6 ]]
then
realpath -z "$search_result" | setsid xclip -selection clipboard
elif [[ $REPLY == 7 ]]
then
main_menu
elif [[ $REPLY == 8 ]]
then
tput clear
else
selection_menu
fi
}
cd /
main_menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment