How to use the command sk (with examples)

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: The find 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 the find command as input to the sk command.
  • sk: The sk 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: The ps command is used to display information about running processes. The aux options provide a detailed list of all processes.
  • |: This symbol is a pipe operator, which passes the output of the ps command as input to the sk command.
  • sk: The sk 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: The sk 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: The find 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 the find command as input to the sk command.
  • --multi: This option enables multi-selection mode in sk, allowing you to select multiple files using Shift + 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.

Related Posts

How to use the command 'bssh' (with examples)

How to use the command 'bssh' (with examples)

The ‘bssh’ command is a GUI tool that allows users to browse for SSH servers on the local network.

Read More
How to use the command `elm` (with examples)

How to use the command `elm` (with examples)

Elm is a functional programming language that compiles to JavaScript and is used for web development.

Read More
Setting an AppArmor policy to complain mode (with examples)

Setting an AppArmor policy to complain mode (with examples)

Use case 1: Set policy to complain mode Code: sudo aa-complain path/to/profile Motivation: Sometimes, when an AppArmor profile is causing certain applications to be denied access to certain resources on a system, it is useful to set the profile to complain mode.

Read More