{"id":22955297,"url":"https://github.com/happycod3r/fzf-tools","last_synced_at":"2025-08-13T02:32:40.258Z","repository":{"id":167729274,"uuid":"643351054","full_name":"happycod3r/fzf-tools","owner":"happycod3r","description":"A ZSH plugin that provides functions which integrate \u0026 bind fuzzy finder capabilities through fzf to certain commands such as ls, man, find and more. ","archived":false,"fork":false,"pushed_at":"2023-11-23T03:39:27.000Z","size":48,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-14T07:59:49.647Z","etag":null,"topics":["bash","functions","fuzzy-finder","fzf","fzf-tools","oh-my-zsh-custom","ohmyzsh","ohmyzsh-plugin","omz","shell","shell-scripts","terminal","v1","zsh"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/happycod3r.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-05-20T22:03:06.000Z","updated_at":"2024-04-10T02:21:36.000Z","dependencies_parsed_at":"2024-01-03T04:17:03.103Z","dependency_job_id":"e076a989-5545-4249-9771-3d914a6238d6","html_url":"https://github.com/happycod3r/fzf-tools","commit_stats":null,"previous_names":["happycod3r/fzf-tools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2Ffzf-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2Ffzf-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2Ffzf-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happycod3r%2Ffzf-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happycod3r","download_url":"https://codeload.github.com/happycod3r/fzf-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229726904,"owners_count":18114834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","functions","fuzzy-finder","fzf","fzf-tools","oh-my-zsh-custom","ohmyzsh","ohmyzsh-plugin","omz","shell","shell-scripts","terminal","v1","zsh"],"created_at":"2024-12-14T16:28:56.127Z","updated_at":"2024-12-14T16:28:56.705Z","avatar_url":"https://github.com/happycod3r.png","language":"Shell","funding_links":[],"categories":["Plugins"],"sub_categories":["ZSH on Windows"],"readme":"﻿# fzf-tools.zsh\n\u003e**FZF-Tools is a Zsh plugin aimed to enhance your command-line workflow by providing interactive selection capabilities through fzf, allowing you to quickly find files, search \u0026 run commands from history, run scripts of many supported types, browse git commits, and more.**\n\n## [Table Of Contents](#toc)\n- [Table Of Contents](#toc)\n- [About](#about)\n- [Install](#install)\n  - [Manual Install](#manual_install)\n  - [Command Line Install](#command_line_install)\n    - [Using Git Clone](#git_clone)\n\t- [Using Curl](#curl)\n- [Usage](#usage)\n  - [oh-my-zsh:](#ohmyzsh)\n  - [stand-alone:](#stand_alone)\n- [Documentation](#documentation)\n  - [fzf-command-widget](#fzf-command-widget)\n  - [fzf-man](#fzf-man)\n  - [fzf-run-command-from-history](#fzf-run-command-from-history)\n  - [fzf-exec-scripts](#fzf-exec-scripts)\n  - [fzf-search-files-on-path](#fzf-search-files-on-path)\n  - [fzf-git-log](#fzf-git-log)\n  - [fzf-ag](#fzf-ag)\n  - [fzf-docker-ps](#fzf-docker-ps)\n  - [fzf-ssh](#fzf-ssh)\n  - [fzf-grep](#fzf-grep)\n  - [fzf-find](#fzf-find)\n- [Contributing](#contributing)\n- [Security](#security)\n- [Contacts](#contacts)\n\n\n## [About](#about)\n\nThe fzf-tools plugin provides functions, key-bindings, and aliases that aim to integrate **fuzzy finder** capabilities into the command line as a default output for certain commands such as `man`, `ls`, `find`, `printenv`, `alias` and others.\nMy aim was to make it so that **fzf** would work without having to manually pipe commands through it, write aliases or explicitly call functions. \nIn other words I wanted to avoid doing the following each time:\n\n```bash\nman -k . | awk '{print $1}' | sort | uniq | fzf | xargs -r man\nls |  --color=auto | fzf\nfind | fzf\nprintenv | fzf\nalias | fzf\n# or...\nalias l=\"ls --color=auto | fzf\"\nalias m=\"man -k . | awk '{print $1}' | sort | uniq | fzf | xargs -r man\"\n```\n\nThere's nothing wrong with doing any of these, but I personally feel that fzf makes a great default feature for certain commands such as `ls` or `man`. It took a lot of trial and error but I finally got everything working smoothly and functioning well. If you have suggestions, ideas etc. consult the [Contacts](#contacts) section.\n\n## [Install](#install)\n\nTo download and install fzf-tools choose an install method and follow the corresponding steps. Once\nfininshed jump to the [Usage](#usage) section.\n\n### [Manual Install](#manual_install)\n\n1. Download and place the ***zsh-toggles*** folder in a location of your choosing.\n2. Next source the script as shown in the [Usage](#usage) section.\n\n### [Command Line Install](#command_line_install)\n\n#### [Using Git Clone:](#git_clone)\n\n1) Open your terminal and navigate to the directory where you want to clone the repository: \n\n```bash\ncd where/I/want/to/install\n```\n\n2) Next run the following command to clone the repository to the chosen location:\n```bash\ngit clone https://github.com/happycod3r/fzf-tools.git\n```\n\n#### [Using Curl:](#curl)\n\n1) Pick a directory to download it to:\n\n```bash\ncd where/I/want/\n```\n\n2) Paste the following line into your terminal and press the `Enter (^M)` key:\n\n```bash\ncurl https://github.com/happycod3r/fzf-tools.git\n```\n\n## [Usage](#usage)\n\n### [oh-my-zsh:](#ohmyzsh)\n\nTo use fzf-tools with oh-my-zsh follow these 2 steps:\n\n1) Install fzf: You need to install fzf on your system. You can find installation instructions for your operating system in the fzf GitHub repository: https://github.com/junegunn/fzf\n2) Simply move the fzf-tools folder to the `~/.oh-my-zsh/custom/plugins` directory and then add ***fzf-tools*** to the ***plugins*** array in your ***~/.zshrc*** file.\n\n```bash\nplugins=(fzf-tools ...)\n```\n\n### [stand-alone:](#stand_alone)\n\nTo use fzf-tools without a plugin manager like oh-my-zsh follow these steps:\n\n  1) Install fzf: You need to install fzf on your system. You can find installation instructions for your operating system in the fzf GitHub repository: https://github.com/junegunn/fzf\n  2) Next put the fzf-tools folder in a place of your choosing then source the ***fzf-tools.zsh*** file in your ***~/.zshrc*** file.\n\n```bash\nsource a/dir/of/your/choosing/fzf-tools.zsh\n```\n\n## [Documentation](#documentation)\n\n\n### [fzf-command-widget](#fzf-command-widget)\n\n\u003e**Defines the 'accept-line' widget function.**\n\n**Please note that the `fzf-command-widget` function modifies the behavior of the Enter key for specific commands, so it may not work as expected in all scenarios! Also, if you decide to add to this or change anything, be cautious when modifying the behavior of core commands like ls and man!**\n\n```bash\nfunction  fzf-command-widget() {\n\tlocal  full_command=$BUFFER\n\tcase  \"$full_command\"  in\n\t\tls*)\n\t\t\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\t\tman*)\n\t\t\tBUFFER=\"fzf-man $full_command\"\n\t\t;;\n\t\tprintenv* | env*)\n\t\t\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\t\tset)\n\t\t\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\t\tgrep*)\n\t\t\tBUFFER=\"$full_command | fzf -i --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\t\tfind*)\t\n\t\t\tBUFFER=\"$full_command | fzf -i --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\t\t'ps aux')\n\t\t\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t\t--preview='echo {}' \\\n\t\t\t\t--preview-window down:10% \\\n\t\t\t\t--layout='reverse-list' \\\n\t\t\t\t--color bg:#222222,preview-bg:#333333\"\n\t\t;;\n\tesac\n\tzle  accept-line\n\t# Uncomment if the long command left over on the previous prompt bothers you.\n\t# $(clear)\n}\n```\n\nThe `fzf-command-widget` function is designed to handle the behavior when the enter key is pressed. It takes the entire command line entered by the user and stores it in a variable called `$full_command`. The case statement then checks for different commands and prefixes the existing command with the required options, arguments, and flags, before piping it through `fzf`.\nFor example, when the user enters `ls -la /path/to/directory` and presses `Enter(^M)`, the `ls` command with options and arguments will be executed as `ls --color=auto -la /path/to/directory | fzf...`\nSimilarly, other commands like `ls`, `man`, `printenv` (including `env` as an alternative), `set`, `grep`, `find` and `ps aux` will be processed with their respective options, arguments, and flags.\nPlease keep in mind that this approach will pass the entire command line through fzf, including options, arguments, and flags. However, it does not perform in-depth parsing or validation of the command structure, so the behavior and correctness of the resulting command are dependent on the proper usage of options and arguments. Due to this, entering invalid commands may have unexpected results. If you're not sure about a command's options and flags you can always consult the man pages. \n\n - After the command line is stored in `$full_command` the `case` statement checks if the command you entered is either `ls`, `man`, `printenv`, `env`, `grep`, `find`, `set` or `ps aux`.\n - For `ls*`, the `BUFFER` is modified to the following command, which pipes the output of `ls` through `fzf`.\n```bash \n\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window right:50% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\"\n```\n - For `man`, the `BUFFER` is modified to `fzf_man $full_command` which is called to pipe the output through `fzf` giving you a list of the manuals to choose from.\n```bash\n\tBUFFER=\"fzf-man $full_command\"\n```\n - For `printenv* | env*`, the `BUFFER` is set to the following command, which pipes the output of `printenv | env` through `fzf`.\n```bash\n\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\"\n```\n - For `grep*`, the `BUFFER` is set to the following command, which sets up `grep` to search and pipe the output through `fzf`.\n```bash\n\tBUFFER=\"$full_command | fzf -i --multi --cycle --no-sort \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\"\n```\n - For `find*`, the `BUFFER` is set to the following command, which executes`find*` and pipes the output through `fzf`.\n```bash\n\tBUFFER=\"$full_command | fzf -i --multi --cycle --no-sort \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\"\n```\n - For `ps aux` the `BUFFER` is set to the following command, which executes `ps aux*` and pipes the output through `fzf`.\n```bash\n\tBUFFER=\"$full_command | fzf --multi --cycle --no-sort \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\"\n```\n - The `zle accept-line` command accepts the modified command line and executes it.\n ---\nNext we have to bind the `accept-line` widget function to the `Enter` key:\n\n```bash\nzle -N fzf-command-widget\nbindkey '^M' fzf-command-widget\n```\n\n -  The `zle -N fzf-command-widget` line creates a new zsh widget from the `fzf_command_widget` function.\n -  The `bindkey '^M' fzf-command-widget` line binds the new widget to the Enter key (`^M`).\n\nMy original approach for detecting specific commands like `ls` and `man` involved using the `precmd` hook which is a function defined by `zsh` that gets invoked before each prompt, so essentially every time the user presses the `Enter key (^M)`, but this wasn't straight forward enough. I found myself tinkering with code more than progressing, so I decided to just create a *widget* and bind it to the `Enter key (^M)`  \n\n------\n\n### [fzf-man](#fzf-man)\n\n\u003e**The `fzf-man` function is called by the `fzf-command-widget` function when it detects that the user has entered the `man`command and not meant to be called externally.**\n\n```bash\nfunction  fzf-man() {\n\tlocal  selected_command\n\tselected_command=$(\n\t\tman  -k . \\\n\t\t|  awk '{print $1}' \\\n\t\t|  sort  \\\n\t\t|  uniq  \\\n\t\t|  fzf  --multi  --cycle  \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10%\n\t)\n\tif [[ -n  \"$selected_command\" ]]; then\n\t\tman  \"$selected_command\"  \\\n\t\t\t|  fzf  --multi  --cycle  --tac  --no-sort  \\\n\t\t\t\t--preview='echo {}'  \\\n\t\t\t\t--preview-window  down:10%  \\\n\t\t\t\t--layout='reverse-list'  \\\n\t\t\t\t--color  bg:#222222,preview-bg:#333333\n\tfi\n}\n```\n\n - If the command retrieved in `fzf-command-widget `is `man`, the `fzf-man` function is called.\n - The `fzf-man` function runs the `man -k` . command to retrieve available manual pages, then extracts the first column (command names) using `awk`, removes duplicates using `sort` and `uniq`, and finally pipes the output through `fzf`.\n - If a command is selected from fzf, it is passed to the man command and piped through `fzf` again to display the corresponding manual page through fuzzy finder for easy searching through the text.\n - The `--tac` flag on the second pipe through to `fzf` is required to display sentences in a legible manner. Without the `--tac` all of the man pages text is displayed backwards. The only downside to `--tac` is that the man pages will be displayed bottom up, so you will start at the bottom and scroll up to reach the beginning. Removing `--tac` fixes this, but then reverses the text as previously mentioned. This behavior is because of `fzf`. To me the benefits of `fzf` outweigh the slight nuisance of having to start at the bottom though.\n - Adding `--layout='reverse-list'`  helps with the scrolling. If a man page is selected the prompt will be displayed at the bottom and this also allows scrolling in a more familiar manner, from top to bottom as well.  \n---\n\n### [fzf-run-command-from-history](#fzf-run-command-from-history)\n\u003e**Allows searching for and executing a command from your command history interactively using fzf.**\n\n```bash\nfunction  fzf-run-cmd-from-history() {\n\tlocal  selected_command\n\tselected_command=$(\n\t\thistory  \\\n\t\t|  awk '{$1=\"\"; print $0}' \\\n\t\t|  awk '!x[$0]++' \\\n\t\t|  fzf  --cycle  --tac +s --no-sort  \\\n\t\t\t--preview 'echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--color bg:#222222,preview-bg:#333333 \\\n\t)\n\tif [[ -n  \"$selected_command\" ]]; then\n\t\teval  \"$selected_command\"\n\tfi\n}\n\nalias  fzhist='fzf-run-cmd-from-history'\n```\n - The `history` command gets the command history of the current session.\n - The first `awk` command removes the line numbers from the history output in order to eval the command down the line.\n - The second `awk` command removes duplicate lines from the output.\n - The output is then piped to `fzf` using the `+s` flag to enable the *multi-select* feature.\n - The `--cycle` flag enables you to easily cycle back to beginning of your history from the end or vice versa. \n - The `--no-sort` flag is also enabled to avoid sorting the results. This way you see your history in the correct order with the last command listed first.\n - The \t`--preview` option is used to show a preview of the selected command using the `echo` command. You can replace `'echo {}` with any other command you want to preview instead.\n - The `--preview-window` option sets the size and position of the preview window. It's at 10% to leave just enough room to display the currently selected command.\n -  The selected command is then stored in the `selected_command` variable.\n - Finally it checks if a command is selected (*i.e., the selected_command variable is not empty*), and if so it is evaluated using eval.\n---\nNote: *Choosing a previous `cd` command from your history may fail to execute as the `fzf-run-command-from-hisory` function doesn't take into account your current position in the directory stack, so if you aren't in the same position that you were originally in when executing the `cd some-dir` command from your history it will fail giving you the following error:\n`cd: no such file or directory: some-dir`\n\n------\n\n### [fzf-exec-scripts](#fzf-exec-scripts)\n\u003e**This command will allow you to search for a script/s within the desired directory and its subdirectories, allowing you to interactively select and execute the desired script/s with their respective interpreters. When more than one script is selected they are all executed consecutively one after the other.**\n\n```bash\nfunction fzf-exec-scripts() {\n\tlocal directory=\"$1\"\n\tshift\n\tlocal file_exts=(\"$@\")\n\n\tif [[ -z \"$directory\" || \"${#file_exts[@]}\" -eq 0 ]]; then\n\t    echo \"Usage: fzf-exec-scripts \u003cdirectory\u003e \u003cfile_extension1\u003e [\u003cfile_extension2\u003e ...]\"\n\t    return 1\n\tfi\n\n\tlocal selected_scripts=()\n\tlocal selected_script\n\tselected_script=$(find \"$directory\" -type f \\( -name \"*.${file_exts[1]}\" $(printf -- \"-o -name '*.%s' \" \"${file_exts[@]:1}\") \\) \\\n\t\t| fzf --multi -m --cycle --tac +s  \\\n\t\t\t\t--preview='echo {}'  \\\n\t\t\t\t--preview-window  down:10%  \\\n\t\t\t\t--layout='reverse-list'  \\\n\t\t\t\t--color  bg:#222222,preview-bg:#333333) \u0026\u0026 selected_scripts=(\"${(f)selected_script}\")\n\n\tif [[ \"${#selected_scripts[@]}\" -eq 0 ]]; then\n\t    echo \"No scripts selected.\"\n\t    return\n\tfi\n\n\tfor script in \"${selected_scripts[@]}\"; do\n\t    chmod +x \"$script\"\n\t    case \"$script\" in\n\t\t    *.sh)\n\t\t\t\tbash  \"$script\"\n\t\t\t;;\n\t\t\t*.zsh)\n\t\t\t\tzsh  \"$script\"\n\t\t\t;; \n\t\t    *.js)\n\t\t        node \"$script\"\n\t        ;;\n\t\t    *.py)\n\t\t\t    python \"$script\"\n\t        ;;\n\t        *.rb)\n\t\t        ruby \"$script\"\n\t        ;;\n\t        *.rs)\n\t\t\t\tfilename=$(basename \"${directory}/${script}\")\n\t\t\t\trustc  \"$script\"\n\t\t\t\t./$filename\n\t\t\t;;\n\t\t    *)\t\n\t\t        echo \"Unsupported file extension: $script\"\n\t\t        return 1\n\t        ;;\n\t    esac\n\tdone\n}\n\nalias fzscripts='fzf-exec-scripts'\n```\n- The `fzf-exec-scripts` function accepts a directory as the first parameter and multiple file extensions as subsequent parameters. The `shift` command is used to remove the first parameter (`$1`) from the list, so that the remaining parameters represent the file extensions.\n- The function checks if both the *directory* and file *extensions* are provided. If either of them is missing, it displays a usage message and returns with an '*unsupported file extension*' error.\n- The `find` command is then used to search for files with the specified file extensions in the specified directory. The `-name` option in `find` is used with logical OR (`-o`) to match files with any of the specified extensions. \n- The resulting file paths are then piped through `fzf` for interactive selection.\n- After selecting the scripts with `fzf` and storing them in the `$selected_scripts` array, we check if any scripts were selected `(\"${#selected_scripts[@]}\" -eq 0)`. If no scripts were selected, we display a message and return.\n- If one or more scripts were selected, we iterate over the `$selected_scripts` array and execute each script individually. The execute permission is set on each script before executing it.\n- The `case` statement determines the file extension of each script and executes it with the corresponding interpreter.\n- The default case of the the `case` statement lets the user know that the interpreter they need to run the selected script isn't installed and/or where to get it.\n\nTo use `fzf-exec-scripts` supply it with the desired directory of your script/s and file extensions as parameters. When providing a file extension/s be sure to leave out the prepended '`.`' on the extension/s as you only need the extension name by it self  (e.g. `.sh` -\u003e `sh` | | `.js` -\u003e `js`) .  For example:\n```bash\nfzf-exec-scripts /path/to/scripts/ sh js py rb \n```\n\n---\n\n### [fzf-search-files-on-path](#fzf-search-files-on-path)\n\u003e **Interactively search for files on a given path.**\n```bash\nfunction  fzf-search-files-on-path() {\n\tlocal  _path=\"$1\"\n\tfind  tree  \"$_path\"  -type  f  \\\n\t\t|  fzf  -i --multim  --cycle  \\\n\t\t\t--preview='echo {}'  \\\n\t\t\t--preview-window  down:10%  \\\n\t\t\t--color  bg:#222222,preview-bg:#333333\n}\n\nalias  fzfop='fzf-search-files-on-path'\n```\n- First the path is stored in the local `$_path` variable.\n- The `find` command is then used to search the given path for all things of type `file` and pipes the results through `fzf`. \n---\n### [fzf-git-log](#fzf-git-log)\n\u003e **Select a commit from git log using fzf.**\n```bash\nfunction  fzf-git-log() {\n\tlocal  selected_commit\n\tselected_commit=$(\\\n\t\tgit log --oneline  |  fzf  --multi  --no-sort  --cycle  \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333 \\\n\t) \u0026\u0026 git  show  \"$selected_commit\"\n}\n\nalias fzgl='fzf-git-log'\n```\n  - With this function, you can select a commit from the git log interactively. \n  - It executes `git log --oneline` to retrieve a concise log of commits, and pipes the output through `fzf`. \n  - Once you choose a commit, it displays the full details of that commit using `git show`.\n---\n\n### [fzf-ag](#fzf-ag)\n\u003e Search for patterns in files using ag (The Silver Searcher) and fzf.\n```bash\nfunction  fzf-ag() {\n\tlocal  selected_file\n\tselected_file=$(\\\n\t\tag \"$1\" . |  fzf  \\\n\t\t\t--multi  --no-sort  --cycle  \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\\\n\t) \u0026\u0026 $EDITOR  \"$selected_file\"\n}\n\nalias fzag='fzf-ag'\n```\n  - This function is similar to `fzf-grep` but uses `ag` (The Silver Searcher) instead of `grep`. \n  - It searches for patterns in files using `ag \"$1\"`, which searches for the specified pattern `($1)` in the current directory. \n  - The search results are then piped through `fzf`, and once you select a file, it opens in your default editor.\n---\n\n### [fzf-docker-ps](#fzf-docker-ps)\n\u003e **Select a Docker container from docker ps interactively using fzf**.\n```bash\nfunction  fzf-docker-ps() {\n\tlocal  selected_container\n\tselected_container=$(docker ps -a  |  fzf  \\\n\t\t--multi  --no-sort  --cycle  \\\n\t\t--preview='echo {}' \\\n\t\t--layout='reverse-list' \\\n\t\t--color bg:#222222,preview-bg:#333333 \\ \n\t\t|  awk '{print $1}') \\\n\t\t\u0026\u0026 docker  logs  \"$selected_container\"\n}\n\nalias fzdps='fzf-docker-ps'\n```\n  - With this function, you can select a Docker container from docker ps interactively.\n  -  It executes `docker ps -a` to list all Docker containers and pipes the output through `fzf`. \n  - Once you select a container, it displays the logs of that container using `docker logs`.\n---\n\n### [fzf-ssh](#fzf-ssh)\n\u003e **Select an SSH host from known_hosts using fzf.**\n```bash\nfunction fzf-ssh() {\n\tlocal selected_host\n\tselected_host=$(\\\n\t\tcat ~/.ssh/known_hosts \\\n\t\t|  cut  -f  1  -d ' ' \\\n\t\t|  sed  -e s/,.*//g |  uniq  |  fzf  --multi  --no-sort  --cycle  \\\n\t\t\t--preview='echo {}' \\\n\t\t\t--preview-window down:10% \\\n\t\t\t--layout='reverse-list' \\\n\t\t\t--color bg:#222222,preview-bg:#333333\\\n\t) \u0026\u0026 ssh  \"$selected_host\"\n}\nalias fzssh='fzf-ssh'\n```\n- This function enables you to select an SSH host from your known_hosts file interactively. \n- It uses `cat`, `cut`, `sed` and `uniq` to read the known_hosts file, extract the hostnames, remove any additional information, and presents them in fzf for selection. \n- Once you choose a host, it initiates an SSH connection using `ssh`.\n---\n### [fzf-grep](#fzf-grep)\n\u003e **Interactively search for patterns in files using grep and fzf.**\n```bash\nfunction  fzf-grep() {\n\tlocal  selected_file\n\tselected_file=$(grep  -Ril \"$1\" . |  fzf  --multi  --no-sort  --cycle  \\\n\t\t--preview='echo {}' \\\n\t\t--preview-window down:10% \\\n\t\t--layout='reverse-list' \\\n\t\t--color bg:#222222,preview-bg:#333333\\\n\t) \u0026\u0026 $EDITOR  \"$selected_file\"\n}\n\nalias fzgrep='fzf-grep'\n```\n  - This function combines `grep` and `fzf` to search for patterns in files interactively. \n  - It uses the `grep -Ril` command to search for the specified pattern `($1)` recursively in the current directory and its subdirectories. \n  - The search results are then piped through `fzf`. \n  - Once you select a file, it opens in your default editor.\n---\n\n### [fzf-find](#fzf-find)\n\u003e**Search for files using find and fzf.**\n```bash\nfunction  fzf-find() {\n\tlocal  selected_file\n\tselected_file=$(find . -type f |  fzf  --multi  --no-sort  --cycle  \\\n\t\t--preview='echo {}' \\\n\t\t--preview-window down:10% \\\n\t\t--layout='reverse-list' \\\n\t\t--color bg:#222222,preview-bg:#333333\\\n\t) \u0026\u0026 $EDITOR  \"$selected_file\"\n}\n\nalias fzfind='fzf-find'\n```\n  - This function allows you to search for files using the `find` command. It pipes the output of `find . -type f` (which searches for files in the current directory and its subdirectories) through `fzf` for interactive selection. \n  - Once you select a file, it opens in your default editor `($EDITOR)`.\n---\n\n\n```bash\nautoload -Uz fzf-command-widget fzf-man fzf-run-cmd-from-history fzf-exec-scripts fzf-search-files-on-path fzf-git-log fzf-ag fzf-docker-ps fzf-ssh fzf-grep fzf-find\n```\nThe `autoload -Uz` command ensures that the functions of this plugin are lazily loaded when they are invoked.\n\n```bash\nif [[ -x  \"$(command  -v fzf)\" ]]; then\n\texport FZF_DEFAULT_COMMAND='ag -g \"\"'\n\texport FZF_DEFAULT_OPTS='-m --preview-window=up:40%:wrap'\nfi\n```\n\nInitializes the `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS` environment variables which can be used to customize fzf's behavior. These are just some example options to start with for the 2 variables, but you can change them to whatever you would prefer.\n\n## [Contributing](#contributing)\nIf you have any feature requests, suggestions or general questions you can reach me via any of the methods listed below in the \"[Contacts](#contact)\" section\n\n## [Security](#security)\n### Reporting a vulnerability or bug?\n\n**Do not submit an issue or pull request**: A general rule of thumb is to never publicly report bugs or vulnerabilities because you might inadvertently reveal it to unethical people who may use it for bad. \nInstead, you can email me directly at: [**paulmccarthy676@gmail.com**](mailto:paulmccarthy676@gmail.com).\nI will deal with the issue privately and submit a patch as soon as possible.\n \n## [Contacts](#contacts)\n\nAuthor: Paul M.\n- Email: [paulmccarthy676@gmail.com](mailto:paulmccarthy676@gmail.com)\n- Github: [https://github.com/happycod3r](https://github.com/happycod3r)\n- Linkedin: [https://www.linkedin.com/in/paul-mccarthy-89165a269/](https://www.linkedin.com/in/paul-mccarthy-89165a269/)\n- Facebook: [https://www.facebook.com/paulebeatz](https://www.facebook.com/paulebeatz)\n\n[Back to top](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycod3r%2Ffzf-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappycod3r%2Ffzf-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycod3r%2Ffzf-tools/lists"}