How to use the command sk (with examples)
The sk
command is a fuzzy finder written in Rust, similar to fzf
. It allows users to quickly search and select items from a list in a terminal environment. The command provides several use cases that can help users efficiently find files, processes, or even specify a search query.
Use case 1: Start skim
on all files in the specified directory
Code:
find path/to/directory -type f | sk
Motivation:
This use case is useful when you want to search for files in a specific directory without navigating the file system manually. By using the find
command in combination with sk
, you can quickly filter and select the desired file.
Explanation:
find path/to/directory
: Thefind
command is used to search for files in the specified directory (path/to/directory
).-type f
: This option specifies that only regular (non-directory) files should be considered in the search.|
: This symbol is a pipe operator, which passes the output of thefind
command as input to thesk
command.sk
: Thesk
command opens the fuzzy finder interface, allowing you to search and select files.
Example output:
/path/to/directory/file1.txt
/path/to/directory/file2.txt
/path/to/directory/file3.txt
Use case 2: Start skim
for running processes
Code:
ps aux | sk
Motivation:
When dealing with a large number of running processes, it can be overwhelming to find and interact with a specific process. By using the ps
command in conjunction with sk
, you can easily filter and select a process based on its attributes.
Explanation:
ps aux
: Theps
command is used to display information about running processes. Theaux
options provide a detailed list of all processes.|
: This symbol is a pipe operator, which passes the output of theps
command as input to thesk
command.sk
: Thesk
command opens the fuzzy finder interface, allowing you to search and select processes.
Example output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 5160 5344 ? Ss 2021 0:09 /sbin/init
root 2 0.0 0.0 0 0 ? S 2021 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 2021 0:00 [rcu_gp]
...
Use case 3: Start skim
with a specified query
Code:
sk --query "query"
Motivation:
Sometimes, you may already have a query in mind and want to start searching immediately. By providing the query directly in the command, you can efficiently find the desired item without having to type it again in the interactive interface.
Explanation:
sk
: Thesk
command opens the fuzzy finder interface.--query "query"
: This option allows you to specify the initial query to be pre-filled in the search bar.
Example output:
(query)
Use case 4: Select multiple files with Shift + Tab
and write to a file
Code:
find path/to/directory -type f | sk --multi > path/to/file
Motivation:
When you need to work with multiple files at once, selecting them individually can be time-consuming. With the --multi
option, you can use keyboard shortcuts to select multiple files simultaneously and redirect their paths to a file for further processing.
Explanation:
find path/to/directory
: Thefind
command is used to search for files in the specified directory (path/to/directory
).-type f
: This option specifies that only regular (non-directory) files should be considered in the search.|
: This symbol is a pipe operator, which passes the output of thefind
command as input to thesk
command.--multi
: This option enables multi-selection mode insk
, allowing you to select multiple files usingShift + Tab
.> path/to/file
: The>
symbol redirects the selected file paths to the specified file (path/to/file
).
Example output:
/path/to/directory/file1.txt
/path/to/directory/file3.txt
Conclusion:
The sk
command provides a powerful way to search and select items in a terminal environment. With its fuzzy finder interface and various options, it offers a convenient and efficient workflow for tasks involving file or process selection. By understanding the different use cases and their corresponding examples, you can leverage the full potential of the sk
command and enhance your productivity.