m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 07:43:39 -05:00

Improve i3 example by allowing FZF_DEFAULT_OPTIONS to be set

HernanIbarraMejia
2025-05-22 18:27:09 +01:00
parent 611f8e2149
commit c106d0a6c1

@@ -116,13 +116,13 @@ ec () {
``` ```
Inspired by the above, suggested by [Matt-A-Bennett](https://github.com/Matt-A-Bennett) (not tested in zsh): Inspired by the above, suggested by [Matt-A-Bennett](https://github.com/Matt-A-Bennett) (not tested in zsh):
```sh ```sh
# Run command/application and choose paths/files with fzf. # Run command/application and choose paths/files with fzf.
# Always return control of the terminal to user (e.g. when opening GUIs). # Always return control of the terminal to user (e.g. when opening GUIs).
# The full command that was used will appear in your history just like any # The full command that was used will appear in your history just like any
# other (N.B. to achieve this I write the shell's active history to # other (N.B. to achieve this I write the shell's active history to
# ~/.bash_history) # ~/.bash_history)
# #
# Usage: # Usage:
# f cd [OPTION]... (hit enter, choose path) # f cd [OPTION]... (hit enter, choose path)
# f cat [OPTION]... (hit enter, choose files) # f cat [OPTION]... (hit enter, choose files)
@@ -573,17 +573,17 @@ fkill() {
```sh ```sh
# fkill - kill processes - list only the ones you can kill. Modified the earlier script. # fkill - kill processes - list only the ones you can kill. Modified the earlier script.
fkill() { fkill() {
local pid local pid
if [ "$UID" != "0" ]; then if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}') pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi fi
if [ "x$pid" != "x" ] if [ "x$pid" != "x" ]
then then
echo $pid | xargs kill -${1:-9} echo $pid | xargs kill -${1:-9}
fi fi
} }
``` ```
@@ -593,7 +593,7 @@ The https://github.com/NullSense/fuzzy-sys project implements frequently used sy
### Git ### Git
List all available git commands and help with [`git-commands`](https://github.com/hankchanocd/git-commands) List all available git commands and help with [`git-commands`](https://github.com/hankchanocd/git-commands)
```sh ```sh
# fbr - checkout git branch # fbr - checkout git branch
@@ -704,7 +704,7 @@ fshow_preview() {
--bind "alt-y:execute:$_gitLogLineToHash | xclip" --bind "alt-y:execute:$_gitLogLineToHash | xclip"
} }
``` ```
Compare against `master` branch with [`git-stack`](https://github.com/hankchanocd/git-stack) Compare against `master` branch with [`git-stack`](https://github.com/hankchanocd/git-stack)
```sh ```sh
# fcs - get git commit sha # fcs - get git commit sha
@@ -753,7 +753,7 @@ Create a gitignore file from [gitignore.io](http://gitignore.io):
https://gist.github.com/phha/cb4f4bb07519dc494609792fb918e167 https://gist.github.com/phha/cb4f4bb07519dc494609792fb918e167
```sh ```sh
# fgst - pick files from `git status -s` # fgst - pick files from `git status -s`
is_in_git_repo() { is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1 git rev-parse HEAD > /dev/null 2>&1
} }
@@ -779,7 +779,7 @@ function git-fixup () {
} }
``` ```
Usage: Usage:
``` ```
git fixup git fixup
@@ -816,10 +816,10 @@ Suggested by [@windisch](https://github.com/windisch).
```sh ```sh
# fjrnl - Search JRNL headlines # fjrnl - Search JRNL headlines
fjrnl() { fjrnl() {
title=$(jrnl --short | fzf --tac --no-sort) && title=$(jrnl --short | fzf --tac --no-sort) &&
jrnl -on "$(echo $title | cut -c 1-16)" $1 jrnl -on "$(echo $title | cut -c 1-16)" $1
} }
``` ```
### ctags ### ctags
@@ -954,13 +954,13 @@ Add support for kubectl completion with fzf
# BASH # BASH
# Tested kubectl version `v1.23.6` # Tested kubectl version `v1.23.6`
# Make all kubectl completion fzf # Make all kubectl completion fzf
command -v fzf >/dev/null 2>&1 && { command -v fzf >/dev/null 2>&1 && {
source <(kubectl completion bash | sed 's#"${requestComp}" 2>/dev/null#"${requestComp}" 2>/dev/null | head -n -1 | fzf --multi=0 #g') source <(kubectl completion bash | sed 's#"${requestComp}" 2>/dev/null#"${requestComp}" 2>/dev/null | head -n -1 | fzf --multi=0 #g')
} }
# ZSH # ZSH
# Make all kubectl completion fzf # Make all kubectl completion fzf
command -v fzf >/dev/null 2>&1 && { command -v fzf >/dev/null 2>&1 && {
source <(kubectl completion zsh | sed 's#${requestComp} 2>/dev/null#${requestComp} 2>/dev/null | head -n -1 | fzf --multi=0 #g') source <(kubectl completion zsh | sed 's#${requestComp} 2>/dev/null#${requestComp} 2>/dev/null | head -n -1 | fzf --multi=0 #g')
} }
``` ```
@@ -968,7 +968,7 @@ Put this in your `.bashrc` or `.zshrc` instead of:
```bash ```bash
source <(kubectl completion bash) source <(kubectl completion bash)
``` ```
It will source kubectl completion with fzf support It will source kubectl completion with fzf support
Examples: Examples:
```bash ```bash
# Will open fzf windows with k8s objects starting with `p` # Will open fzf windows with k8s objects starting with `p`
@@ -986,10 +986,10 @@ This was tested with (should work with all commands):
- [x] version `v1.23.6` - [x] version `v1.23.6`
- [x] bash - [x] bash
- [x] zsh - [x] zsh
- commands: - commands:
- [x] get - [x] get
- [x] get pods - [x] get pods
- [x] describe - [x] describe
- [x] describe pods - [x] describe pods
- [x] logs - [x] logs
@@ -1007,7 +1007,7 @@ The below [passfzf](https://git.sr.ht/~mlaparie/passfzf) script is a wrapper for
# to add or generate new passwords, and synchronize them (with git). # to add or generate new passwords, and synchronize them (with git).
# Dependencies: fd, fzf, pass # Dependencies: fd, fzf, pass
# Optional dependencies: git, pass-tomb # Optional dependencies: git, pass-tomb
# #
# MIT License, Copyright © [2022] Mathieu Laparie <mlaparie [at] disr [dot] it> # MIT License, Copyright © [2022] Mathieu Laparie <mlaparie [at] disr [dot] it>
store="$HOME/.password-store/" store="$HOME/.password-store/"
@@ -1318,48 +1318,48 @@ echo install > $tmp_file
### Homebrew Cask ### Homebrew Cask
```sh ```sh
# Install or open the webpage for the selected application # Install or open the webpage for the selected application
# using brew cask search as input source # using brew cask search as input source
# and display a info quickview window for the currently marked application # and display a info quickview window for the currently marked application
install() { install() {
local token local token
token=$(brew search --casks "$1" | fzf-tmux --query="$1" +m --preview 'brew info {}') token=$(brew search --casks "$1" | fzf-tmux --query="$1" +m --preview 'brew info {}')
if [ "x$token" != "x" ] if [ "x$token" != "x" ]
then then
echo "(I)nstall or open the (h)omepage of $token" echo "(I)nstall or open the (h)omepage of $token"
read input read input
if [ $input = "i" ] || [ $input = "I" ]; then if [ $input = "i" ] || [ $input = "I" ]; then
brew install --cask $token brew install --cask $token
fi fi
if [ $input = "h" ] || [ $input = "H" ]; then if [ $input = "h" ] || [ $input = "H" ]; then
brew home $token brew home $token
fi fi
fi fi
} }
``` ```
```sh ```sh
# Uninstall or open the webpage for the selected application # Uninstall or open the webpage for the selected application
# using brew list as input source (all brew cask installed applications) # using brew list as input source (all brew cask installed applications)
# and display a info quickview window for the currently marked application # and display a info quickview window for the currently marked application
uninstall() { uninstall() {
local token local token
token=$(brew list --casks | fzf-tmux --query="$1" +m --preview 'brew info {}') token=$(brew list --casks | fzf-tmux --query="$1" +m --preview 'brew info {}')
if [ "x$token" != "x" ] if [ "x$token" != "x" ]
then then
echo "(U)ninstall or open the (h)omepae of $token" echo "(U)ninstall or open the (h)omepae of $token"
read input read input
if [ $input = "u" ] || [ $input = "U" ]; then if [ $input = "u" ] || [ $input = "U" ]; then
brew uninstall --cask $token brew uninstall --cask $token
fi fi
if [ $input = "h" ] || [ $token = "h" ]; then if [ $input = "h" ] || [ $token = "h" ]; then
brew home $token brew home $token
fi fi
fi fi
} }
``` ```
### DNF ### DNF
@@ -1440,7 +1440,7 @@ if tmp_file="$(mktemp --tmpdir "${basename}".XXXXXX)"; then
--marker=' ' \ --marker=' ' \
--preview-window='right,67%,wrap' \ --preview-window='right,67%,wrap' \
--preview="${INS_PRVW} {1}" \ --preview="${INS_PRVW} {1}" \
--bind="enter:execute(if grep -q 'in' \"${tmp_file}\"; then sudo dnf install {+}; --bind="enter:execute(if grep -q 'in' \"${tmp_file}\"; then sudo dnf install {+};
elif grep -q 'rm' \"${tmp_file}\"; then sudo dnf remove {+}; \ elif grep -q 'rm' \"${tmp_file}\"; then sudo dnf remove {+}; \
elif grep -q 'up' \"${tmp_file}\"; then sudo dnf upgrade {+}; fi; \ elif grep -q 'up' \"${tmp_file}\"; then sudo dnf upgrade {+}; fi; \
read -s -r -n1 -p $'\n${BLUE}Press any key to continue...' && printf '\n')" \ read -s -r -n1 -p $'\n${BLUE}Press any key to continue...' && printf '\n')" \
@@ -1451,7 +1451,7 @@ if tmp_file="$(mktemp --tmpdir "${basename}".XXXXXX)"; then
--bind="alt-m:execute(sudo dnf makecache;read -s -r -n1 -p $'\n${BLUE}Press any key to continue...' && printf '\n')" \ --bind="alt-m:execute(sudo dnf makecache;read -s -r -n1 -p $'\n${BLUE}Press any key to continue...' && printf '\n')" \
--bind="alt-?:preview(printf \"${fhelp[0]}\")" \ --bind="alt-?:preview(printf \"${fhelp[0]}\")" \
--bind="ctrl-a:select-all" --bind="ctrl-a:select-all"
rm -f "${tmp_file}" &> /dev/null rm -f "${tmp_file}" &> /dev/null
else else
printf 'Error: Failed to create tmp file. $TMPDIR (or /tmp if $TMPDIR is unset) may not be writable.\n' >&2 printf 'Error: Failed to create tmp file. $TMPDIR (or /tmp if $TMPDIR is unset) may not be writable.\n' >&2
@@ -1464,8 +1464,8 @@ fi
![](https://user-images.githubusercontent.com/114978689/201288486-af070edc-b1c4-4535-bb48-1d51453f501d.png) ![](https://user-images.githubusercontent.com/114978689/201288486-af070edc-b1c4-4535-bb48-1d51453f501d.png)
```sh ```sh
# CLR=$(for i in {0..7}; do echo "tput setaf $i"; done) # CLR=$(for i in {0..7}; do echo "tput setaf $i"; done)
BLK=\$(tput setaf 0); RED=\$(tput setaf 1); GRN=\$(tput setaf 2); YLW=\$(tput setaf 3); BLU=\$(tput setaf 4); BLK=\$(tput setaf 0); RED=\$(tput setaf 1); GRN=\$(tput setaf 2); YLW=\$(tput setaf 3); BLU=\$(tput setaf 4);
MGN=\$(tput setaf 5); CYN=\$(tput setaf 6); WHT=\$(tput setaf 7); BLD=\$(tput bold); RST=\$(tput sgr0); MGN=\$(tput setaf 5); CYN=\$(tput setaf 6); WHT=\$(tput setaf 7); BLD=\$(tput bold); RST=\$(tput sgr0);
AWK_VAR="awk -v BLK=${BLK} -v RED=${RED} -v GRN=${GRN} -v YLW=${YLW} -v BLU=${BLU} -v MGN=${MGN} -v CYN=${CYN} -v WHT=${WHT} -v BLD=${BLD} -v RST=${RST}" AWK_VAR="awk -v BLK=${BLK} -v RED=${RED} -v GRN=${GRN} -v YLW=${YLW} -v BLU=${BLU} -v MGN=${MGN} -v CYN=${CYN} -v WHT=${WHT} -v BLD=${BLD} -v RST=${RST}"
@@ -1474,9 +1474,9 @@ fzf-flatpak-install-widget() {
flatpak remote-ls flathub --cached --columns=app,name,description \ flatpak remote-ls flathub --cached --columns=app,name,description \
| awk -v cyn=$(tput setaf 6) -v blu=$(tput setaf 4) -v bld=$(tput bold) -v res=$(tput sgr0) \ | awk -v cyn=$(tput setaf 6) -v blu=$(tput setaf 4) -v bld=$(tput bold) -v res=$(tput sgr0) \
'{ '{
app_info=""; app_info="";
for(i=2;i<=NF;i++){ for(i=2;i<=NF;i++){
app_info=cyn app_info" "$i app_info=cyn app_info" "$i
}; };
print blu bld $2" -" res app_info "|" $1 print blu bld $2" -" res app_info "|" $1
}' \ }' \
@@ -1516,12 +1516,12 @@ fzf-flatpak-uninstall-widget() {
--bind "alt-r:change-prompt(Run > )+execute-silent(touch /tmp/run && rm -r /tmp/uns)" \ --bind "alt-r:change-prompt(Run > )+execute-silent(touch /tmp/run && rm -r /tmp/uns)" \
--bind "alt-u:change-prompt(Uninstall > )+execute-silent(touch /tmp/uns && rm -r /tmp/run)" \ --bind "alt-u:change-prompt(Uninstall > )+execute-silent(touch /tmp/uns && rm -r /tmp/run)" \
--bind "enter:execute( --bind "enter:execute(
if [ -f /tmp/uns ]; then if [ -f /tmp/uns ]; then
flatpak uninstall {3}; flatpak uninstall {3};
elif [ -f /tmp/run ]; then elif [ -f /tmp/run ]; then
flatpak run {3}; flatpak run {3};
fi fi
)" # same as the install one but when pressed entered the message is something like this )" # same as the install one but when pressed entered the message is something like this
# "Proceed with these changes to the system installation? [Y/n]:" but it will uninstall the selected app weird but idk y # "Proceed with these changes to the system installation? [Y/n]:" but it will uninstall the selected app weird but idk y
rm -f /tmp/{uns,run} &> /dev/null rm -f /tmp/{uns,run} &> /dev/null
zle reset-prompt zle reset-prompt
@@ -1809,9 +1809,9 @@ Function b() {
def ancestors: while(. | length >= 2; del(.[-1,-2])); def ancestors: while(. | length >= 2; del(.[-1,-2]));
. as `$in | paths(.url?) as `$key | `$in | getpath(`$key) | {name,url, path: [`$key[0:-2] | ancestors as `$a | `$in | getpath(`$a) | .name?] | reverse | join(\`"/\`") } | .path + \`"/\`" + .name + \`"|\`" + .url . as `$in | paths(.url?) as `$key | `$in | getpath(`$key) | {name,url, path: [`$key[0:-2] | ancestors as `$a | `$in | getpath(`$a) | .name?] | reverse | join(\`"/\`") } | .path + \`"/\`" + .name + \`"|\`" + .url
"@ "@
Get-Content "$Bookmarks" | jq -r "$JqScript" ` Get-Content "$Bookmarks" | jq -r "$JqScript" `
| ForEach-Object { | ForEach-Object {
$_ -replace "(.*)\|(.*)", "`$1`t`e[36m`$2`e[0m" $_ -replace "(.*)\|(.*)", "`$1`t`e[36m`$2`e[0m"
} ` } `
| fzf --ansi ` | fzf --ansi `
@@ -1989,8 +1989,8 @@ bindkey "${FZF_MARKER_PLACEHOLDER_KEY:-\C-v}" _fzf_marker_placeholder_widget
### Search for academic PDFs by author, title, journal, institution ### Search for academic PDFs by author, title, journal, institution
Search for all pdf files. FZF will match the query against any text found on the first page of the PDF. For instance, one can query for author names, article title, journal, institutions, keywords. It works by extracting the text on the first page of the PDF using ``pdftotext``. Search for all pdf files. FZF will match the query against any text found on the first page of the PDF. For instance, one can query for author names, article title, journal, institutions, keywords. It works by extracting the text on the first page of the PDF using ``pdftotext``.
The selected file is then opened by the default pdf viewer. The selected file is then opened by the default pdf viewer.
Requires the [pdftotext](https://en.wikipedia.org/wiki/Pdftotext) command line tool. Tested on Ubuntu 17.10 on bash and zsh. Requires the [pdftotext](https://en.wikipedia.org/wiki/Pdftotext) command line tool. Tested on Ubuntu 17.10 on bash and zsh.
@@ -2150,6 +2150,10 @@ Display in a floating window. Add this to your i3 config file (this example uses
bindsym $mod+d exec --no-startup-id termite -t 'fzf-menu' -e 'i3-dmenu-desktop --dmenu=fzf' bindsym $mod+d exec --no-startup-id termite -t 'fzf-menu' -e 'i3-dmenu-desktop --dmenu=fzf'
for_window [title="fzf-menu"] floating enable for_window [title="fzf-menu"] floating enable
``` ```
This, however, will likely not use `FZF_DEFAULT_OPTIONS` because i3-dmenu-desktop launches fzf in a non-interactive shell, so files like .bashrc and .zshrc won't be sourced. If this is a problem for you, you can forcibly start an interactive shell. Here is an example with zsh (using urxvt instead of termite):
```
bindsym $mod+d exec --no-startup-id urxvt -title 'fzf-menu' -e i3-dmenu-desktop --dmenu='zsh -i -c fzf'
```
### Man pages ### Man pages
Quickly display a man page using fzf and fd. Quickly display a man page using fzf and fd.
@@ -2204,8 +2208,8 @@ cat $* | col -bx | bat -l man -p --paging always
``` ```
#### fzf-man-pages widget (for zsh) #### fzf-man-pages widget (for zsh)
Same functionality as above Same functionality as above
- with colored and syntax higlighting - with colored and syntax higlighting
- doesn't exit or close fzf when pressed enter - doesn't exit or close fzf when pressed enter
![](https://user-images.githubusercontent.com/114978689/201280168-550fe07f-a26a-4f8f-8ec9-3c1be05b3316.png) ![](https://user-images.githubusercontent.com/114978689/201280168-550fe07f-a26a-4f8f-8ec9-3c1be05b3316.png)
@@ -2268,7 +2272,7 @@ exec alacritty --class="fzf-menu" -e bash -c "fzf-tmux -m $* < /proc/$$/fd/0 | a
dmenu_path | ~/.local/bin/fzfmenu | bash dmenu_path | ~/.local/bin/fzfmenu | bash
``` ```
( You can use anything other than `dmenu_path` that gets a list of entries in `$PATH` too.) ( You can use anything other than `dmenu_path` that gets a list of entries in `$PATH` too.)
2. To use for `Ctrl-t` for a floating menu from terminal 2. To use for `Ctrl-t` for a floating menu from terminal
**For bash** **For bash**
```bash ```bash
__fzfmenu__() { __fzfmenu__() {
@@ -2310,7 +2314,7 @@ download fzf-nova folder as a whole and follow the instructions in fzf-nova scri
[Reference video](https://www.youtube.com/watch?v=8SqakfCSzQk) [Reference video](https://www.youtube.com/watch?v=8SqakfCSzQk)
credits @gotbletu credits @gotbletu
### fzf as dmenu replacement ### fzf as dmenu replacement
@@ -2451,13 +2455,13 @@ This works with `execute-silent` but not with `execute`, presumably because `exe
### Todoist CLI ### Todoist CLI
- Todoist CLI task filitring and preview - Todoist CLI task filitring and preview
```ps ```ps
todoist --namespace --project-namespace list | fzf --preview 'todoist show {1}' | cut -d ' ' -f 1 | tr '\n' ' ' todoist --namespace --project-namespace list | fzf --preview 'todoist show {1}' | cut -d ' ' -f 1 | tr '\n' ' '
``` ```
- The command used for preview is `todoist show {1}` - The command used for preview is `todoist show {1}`
- The `show` option is used to show the task details - The `show` option is used to show the task details
- The `{1}` represents the first feild in the line -> Task ID - The `{1}` represents the first feild in the line -> Task ID
### Dictcc Translation ### Dictcc Translation