Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce feature to search for processes #216

Merged
merged 26 commits into from Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6b4c2bc
Completion for PIDs
cr-mitmit Dec 30, 2021
4ff8558
Using fzf_pids_opts to configure fzf when searching for pids
cr-mitmit Dec 30, 2021
29b8562
Using existing token to initialize search
cr-mitmit Dec 30, 2021
802943c
Adding preview
cr-mitmit Jan 4, 2022
abba719
First PS line output is header
cr-mitmit Jan 4, 2022
4e675d0
Show user name in preview
cr-mitmit Jan 4, 2022
434117e
Rename pids to processes
cr-mitmit Jan 4, 2022
37416aa
Ugly version, but works
cr-mitmit Jan 7, 2022
6b467f5
Better output fields
cr-mitmit Jan 7, 2022
7c16fbe
Output field just shows RSS now, but without formatting
cr-mitmit Jan 8, 2022
6070633
Readme change, adding start time to process preview
cr-mitmit Jan 9, 2022
f7e70d5
Replace AWK with built in fish functions to reduce dependencies
cr-mitmit Jan 10, 2022
af87415
Merge branch 'main' into cr-mitmit/main
PatrickF1 Jan 15, 2022
014ba14
fix command description and whitespace
PatrickF1 Jan 15, 2022
0573763
include in readme
PatrickF1 Jan 15, 2022
5a74bc0
update preview window in readme
PatrickF1 Jan 27, 2022
f12b091
swap rss with start to better organize preview columns
PatrickF1 Jan 27, 2022
61621f9
use Ctrl+Option+P instead
PatrickF1 Jan 29, 2022
92fc330
fix extra # in comment
PatrickF1 Jan 29, 2022
2dba29f
test for outputting correct pid on multi selection; fix a bug with qu…
PatrickF1 Jan 29, 2022
ef14760
switch to %mem
PatrickF1 Jan 29, 2022
0c0a23f
fix query becoming --header-lines=1
PatrickF1 Jan 29, 2022
2ef89f1
preview: add parent pid, go back to resident set size
PatrickF1 Jan 29, 2022
6ad9ff7
remove test; add it back in later since it needs to be modified for s…
PatrickF1 Jan 29, 2022
5fb8a96
remove --multi
PatrickF1 Jan 29, 2022
680a4c8
small typo
PatrickF1 Jan 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions functions/_fzf_configure_bindings_help.fish
Expand Up @@ -12,6 +12,7 @@ DESCRIPTION
Search git status | Ctrl+Alt+S (S for status) | --git_status
Search history | Ctrl+R (R for reverse) | --history
Search variables | Ctrl+V (V for variable) | --variables
Search processes | Ctrl+O (O for prOcess) | --processes
An option with a key sequence value overrides the binding for its feature, while an option
without a value disables the binding. A feature that is not customized retains its default
menomonic binding specified above. Key bindings are installed for default and insert modes.
Expand Down
21 changes: 21 additions & 0 deletions functions/_fzf_search_processes.fish
@@ -0,0 +1,21 @@
function _fzf_search_processes --description "Search pid for all running commands"
PatrickF1 marked this conversation as resolved.
Show resolved Hide resolved
set fzf_arguments --multi --ansi $fzf_processes_opts
PatrickF1 marked this conversation as resolved.
Show resolved Hide resolved
set token (commandline --current-token)
# expand any variables or leading tilde (~) in the token
PatrickF1 marked this conversation as resolved.
Show resolved Hide resolved
#set expanded_token (eval echo -- $token)

set pid_selected (
ps -A -opid,command | \
PatrickF1 marked this conversation as resolved.
Show resolved Hide resolved
_fzf_wrapper --query $token \
--header-lines=1 \
--preview='ps -o pid,user,%cpu,time,rss,command -p {1}' \
PatrickF1 marked this conversation as resolved.
Show resolved Hide resolved
$fzf_arguments | \
awk '{print $1}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come you still need awk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The output from FZF is the entire line, but I'm trying to extract just the PID here to be useful for commands such as "kill". the awk here is simply extracting the pid from the selected line

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so we want to reduce dependencies so you could just use standard fish functions to do this. Check out how I did it in _fzf_search_git_log

)

if test $status -eq 0
commandline --current-token --replace -- (string escape -- $pid_selected)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found a bug: this works for one process but not multiple. probably should be doing $process_selected)[1]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, is string escape necessary?

end

commandline --function repaint
end
8 changes: 5 additions & 3 deletions functions/fzf_configure_bindings.fish
Expand Up @@ -4,7 +4,7 @@ function fzf_configure_bindings --description "Installs the default key bindings
# no need to install bindings if not in interactive mode or running tests
status is-interactive || test "$CI" = true; or return

set options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'variables=?'
set options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'variables=?' 'processes=?'
argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null
if test $status -ne 0
echo "Invalid option or a positional argument was provided." 1>&2
Expand All @@ -15,13 +15,14 @@ function fzf_configure_bindings --description "Installs the default key bindings
return
else
# Initialize with default key sequences and then override or disable them based on flags
# index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = variables
set key_sequences \e\cf \e\cl \e\cs \cr \cv # \c = control, \e = escape
# index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = variables, 6 = processes
set key_sequences \e\cf \e\cl \e\cs \cr \cv \co # \c = control, \e = escape
set --query _flag_directory && set key_sequences[1] "$_flag_directory"
set --query _flag_git_log && set key_sequences[2] "$_flag_git_log"
set --query _flag_git_status && set key_sequences[3] "$_flag_git_status"
set --query _flag_history && set key_sequences[4] "$_flag_history"
set --query _flag_variables && set key_sequences[5] "$_flag_variables"
set --query _flag_processes && set key_sequences[6] "$_flag_processes"

# If fzf bindings already exists, uninstall it first for a clean slate
if functions --query _fzf_uninstall_bindings
Expand All @@ -34,6 +35,7 @@ function fzf_configure_bindings --description "Installs the default key bindings
test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status
test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history
test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] "$_fzf_search_vars_command"
test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] _fzf_search_processes
end

function _fzf_uninstall_bindings --inherit-variable key_sequences
Expand Down