junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.14k stars 2.37k forks source link

fzf launching gui applications #2115

Closed rayiik closed 4 years ago

rayiik commented 4 years ago

Info

Problem / Steps to reproduce

first off let me say i am very new to linux and programming in general so this may not be a fzf issue but rather my script i will post all relevant files. i have made a script that searches through my path and lists all available commands (using fzf), however as i scroll through them if i am in xsererver it launches the program as i browse, so if i have a bunch of gui commands it will open a ton of programs while browsing commands. this isn't a huge issue as i dont spend a lot of time in a graphical environment but i figured this could either be used or a solution found. programs involved : fzf nvimpager man moreman and i use nvimpager as my default man cat and man pager (which lets me run vim apps from within fzf and man pages which allows me to follow links within the manpages) script :

coms () {
case "$PATH" in
  (*[!:]:) PATH="$PATH:" ;;
esac

set -f; IFS=:
for dir in $PATH; do
  set +f
  [ -z "$dir" ] && dir="."
  for file in "$dir"/*; do
    if [ -x "$file" ] && ! [ -d "$file" ]; then
        printf '%s = %s\n' "${file##*/}" "$file"
    fi
  done
done
}

fcomclean () {
unset dir
unset file
}

cmmd () {
    (FZF_DEFAULT_COMMAND='rg -uu . --pretty --files')
    "coms" |\
        awk '{print $1}' | \
        sort -u | \
        fzf \
        --bind="ctrl-h:execute(moreman {})" \
        --preview="moreman {}" \
    --print-query

}

cmmd
fcomclean

my fzf default config is :


export FZF_DEFAULT_COMMAND="rg -uu --pretty --files --column -H"
export FZF_ALT_COMMAND="rg -uu --pretty --files-with-matches . --column -H"
export FZF_DEFAULT_OPTS="--bind='ctrl-s:preview-page-down' \
    --bind='ctrl-a:preview-page-up' \
    --bind='ctrl-u:half-page-up' \
    --bind='ctrl-d:half-page-down' \
    --bind='alt-a:toggle-all' \
        --bind='ctrl-l:clear-screen' \
    --bind='ctrl-h:execute(moreman {})' \
        --bind='ctrl-p:toggle-preview' \
        --bind='ctrl-v:execute(nvimpager {})' \
    --tiebreak='length,index' \
    --exact \
    --info='inline' \
    --cycle \
    --height=85 \
    --multi \
    --ansi \
    --color=fg:#af5fff,bg:#121212,hl:#f74204 \
    --color=info:#cf5300,prompt:#ff0511,pointer:#afd7ff \
    --color=fg+:#85e63a,bg+:#262626,hl+:#ae11d1 \
    --color=marker:#14f73e,spinner:#2c81d1,header:#00ffff \
    --color=preview-fg:#d426cb,border:#ff00d7 \
    --color=preview-bg:#0e001f \
        --preview='bat {}'"

and my rg default is :


--max-columns=150
--max-columns-preview
--glob=!git/*
--glob=!/sys/*
--glob=!/run/*
--glob=!/var/*
--glob=!/proc/*
--glob=!/tmp/*
--pretty
-H
--colors=match:fg:magenta
--colors=line:fg:cyan
--colors=path:fg:green
--type-add=shell:*.sh 

as i said i'v only been on linux and doing any kind of programming for about 2 months so if there's an error in my script please let me know or if its something i could leverage (interactively launching programs) id like to know as well.

Ps. thanks for the formatting advice.

junegunn commented 4 years ago

Please reformat your post to make it more readable.

rayiik commented 4 years ago

Hey so I'm pretty sure it has to do with the preview window as when I toggle off and then on on acommand with a GUI it launches it as a BG process (only on desktop it pops to the front)

rayiik commented 4 years ago

Although its only launching some GUI for sure linguist-qt4\5 at config and some gtk binaries and seems to be preview windows related when I toggle on it opens and codes when toggled off

rayiik commented 4 years ago

So I've dug a little deeper and found something I missed before. The preview window generates its preview by executing the command and displaying the results. In the example above the script generates a list of commands from the $PATH variable and when viewing them in the preview window it executes each command it goes over. So I guess my question is, is there a way to either sandbox the commands to prevent them from doing a real execute like --dry-run-preview?

junegunn commented 4 years ago

Preview option is not for interactive programs or GUI programs.

I don't know what moreman is, so I can't really answer your question, but whatever it is, it all boils down to finding the right command for generating preview content in plain text.

You might want to read through https://github.com/junegunn/fzf#preview-window

rayiik commented 4 years ago

Moreman is a python program that uses either man page or generates a manpage based on the —help flag while I understand that it’s not for GUI programs my list just happens to a handful of GUI programs I’m just wording isn’t the actually execution of the command leave the user open to terminal escape injection? Hence my asking if there’s a way to sandbox the output?