summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-11-29 17:49:48 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-11-29 17:50:53 +0900
commitbd2763d8636bbacb00e57c8cd15b642eedd04891 (patch)
tree0037391d1bd3a5d22aea34258519ddee2d3aad2d
parentb2bb22d8839ca441e972d937b1b940dd29aae66f (diff)
Add bash completion for kill command
-rw-r--r--README.md12
-rw-r--r--fzf-completion.bash15
2 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index 88e00e7b..0f071e71 100644
--- a/README.md
+++ b/README.md
@@ -270,8 +270,8 @@ over time*
### bash
-Fuzzy completion can be triggered if the word before the cursor ends
-with the trigger sequence which is by default `**`.
+Fuzzy completion for files and directories can be triggered if the word before
+the cursor ends with the trigger sequence which is by default `**`.
- `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`
@@ -299,6 +299,14 @@ cd **<TAB>
cd ~/github/fzf**<TAB>
```
+Fuzzy completion for PIDs are provided for kill command. In this case
+there is no trigger sequence, just press tab key after kill command.
+
+```sh
+# Can select multiple processes with <TAB> or <Shift-TAB> keys
+kill -9 <TAB>
+```
+
#### Settings
```sh
diff --git a/fzf-completion.bash b/fzf-completion.bash
index 6697b372..beb39eef 100644
--- a/fzf-completion.bash
+++ b/fzf-completion.bash
@@ -83,6 +83,18 @@ _fzf_dir_completion() {
""
}
+_fzf_kill_completion() {
+ local selected
+ tput sc
+ selected=$(ps -ef | sed 1d | fzf -m | awk '{print $2}' | tr '\n' ' ')
+ tput rc
+
+ if [ -n "$selected" ]; then
+ COMPREPLY=( "$selected" )
+ return 0
+ fi
+}
+
complete -F _fzf_opts_completion fzf
# Directory
@@ -108,3 +120,6 @@ for cmd in "
complete -F _fzf_all_completion -o default -o bashdefault $cmd
done
+# Kill completion
+complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
+