### Start Emacs using exec Source: https://fishshell.com/docs/current/cmds/exec.html This example demonstrates starting the emacs text editor, which replaces the current fish shell. The session will terminate when emacs exits. ```fish exec emacs ``` -------------------------------- ### Example fish_prompt with svn info Source: https://fishshell.com/docs/current/cmds/fish_svn_prompt.html A basic example demonstrating how to include Subversion information in the fish prompt. ```fish function fish_prompt ... printf '%s %s$' $PWD (fish_svn_prompt) end ``` -------------------------------- ### Get Help with Commands Source: https://fishshell.com/docs/current/tutorial.html Use 'man' to view documentation for commands in the terminal or 'help' to open Fish's documentation in a web browser. This example shows 'man set'. ```fish > man set set - handle shell variables Synopsis... ``` -------------------------------- ### Conditional execution with 'and' and 'or' Source: https://fishshell.com/docs/current/cmds/and.html This example demonstrates chaining commands: 'make' is run, and if it succeeds, 'make install' is executed. If either of these fail, 'make clean' is run. ```fish make; and make install; or make clean ``` -------------------------------- ### Start Fish Shell Source: https://fishshell.com/docs/current/cmds/fish.html To simply start an interactive fish shell session. ```bash fish ``` -------------------------------- ### Example output interpretation Source: https://fishshell.com/docs/current/cmds/time.html This example demonstrates the output format of the `time` command, showing wall-clock time and CPU time breakdowns for fish and external processes. ```fish > time string repeat -n 10000000 y\n | command grep y >/dev/null ________________________________________________________ Executed in 805.98 millis fish external usr time 798.88 millis 763.88 millis 34.99 millis sys time 141.22 millis 40.20 millis 101.02 millis ``` -------------------------------- ### fish_delta Output Example Source: https://fishshell.com/docs/current/cmds/fish_delta.html An example output from running fish_delta, showing new and changed files, along with diff information for a changed completion file. ```fish > fish_delta New: /home/alfa/.config/fish/functions/battery.fish Changed: /home/alfa/.config/fish/test/completions/cargo.fish --- /home/alfa/.config/fish/test/completions/cargo.fish 2022-09-02 12:57:55.579229959 +0200 +++ /usr/share/fish/completions/cargo.fish 2022-09-25 17:51:53.000000000 +0200 # the output of `diff` follows ``` -------------------------------- ### Get current login information Source: https://fishshell.com/docs/current/cmds/prompt_login.html This example demonstrates how to directly call the `prompt_login` command to retrieve the current login information, typically displayed as 'user@host'. ```fish prompt_login ``` -------------------------------- ### psub Example: Highlighting Preprocessed C Code Source: https://fishshell.com/docs/current/cmds/psub.html This example shows how to use psub with the -f and -s options to highlight preprocessed C code, specifying a custom suffix for the temporary file. ```fish source-highlight -f esc (cpp main.c | psub -f -s .c) ``` -------------------------------- ### psub Example: Comparing Sorted Files Source: https://fishshell.com/docs/current/cmds/psub.html This example demonstrates how to use psub to compare the sorted versions of two files by passing their sorted outputs to the diff command. ```fish diff (sort a.txt | psub) (sort b.txt | psub) ``` -------------------------------- ### nextd command example Source: https://fishshell.com/docs/current/cmds/nextd.html Demonstrates the usage of nextd by navigating through directories and then moving forward in the history. ```bash cd /usr/src # Working directory is now /usr/src cd /usr/src/fish-shell # Working directory is now /usr/src/fish-shell prevd # Working directory is now /usr/src nextd # Working directory is now /usr/src/fish-shell COPY ``` -------------------------------- ### Simple Fish Prompt Example Source: https://fishshell.com/docs/current/cmds/fish_prompt.html A basic example of a fish_prompt function that displays the current user, hostname, and directory, with the directory color-coded. It utilizes built-in fish variables like $USER and $hostname for simplicity. ```fish function fish_prompt -d "Write out the prompt" # This shows up as USER@HOST /home/user/ >, with the directory colored # $USER and $hostname are set by fish, so you can just use them # instead of using `whoami` and `hostname` printf '%s@%s %s%s%s > ' $USER $hostname \ (set_color $fish_color_cwd) (prompt_pwd) (set_color --reset) end ``` -------------------------------- ### Configure config.fish Source: https://fishshell.com/docs/current/tutorial.html Example of a config.fish file showing how to set environment variables and define functions. Fish executes commands in ~/.config/fish/config.fish on startup. ```fish > cat ~/.config/fish/config.fish set -x PATH $PATH /sbin/ function ll ls -lh $argv end ``` -------------------------------- ### fish-shell switch command example Source: https://fishshell.com/docs/current/cmds/switch.html An example demonstrating how to use the switch command to classify an animal based on the value of the `$animal` variable. It includes a default case for unknown values. ```fish switch $animal case cat echo evil case wolf dog human moose dolphin whale echo mammal case duck goose albatross echo bird case shark trout stingray echo fish case '*' echo I have no idea what a $animal is end ``` -------------------------------- ### Set selection start and end with commandline Source: https://fishshell.com/docs/current/relnotes.html Demonstrates using the `commandline` builtin with new options `--selection-start` and `--selection-end` to programmatically set the start and end points of the current selection on the command line. ```fish commandline --selection-start 10 --selection-end 20 ``` -------------------------------- ### isatty examples: terminal output Source: https://fishshell.com/docs/current/cmds/isatty.html These examples demonstrate cases where isatty should return a zero exit status, indicating a terminal. ```fish isatty isatty stdout isatty 2 echo | isatty 1 ``` -------------------------------- ### Fish Prompt Example with fish_status_to_signal Source: https://fishshell.com/docs/current/cmds/fish_status_to_signal.html An example of how to use fish_status_to_signal within a custom fish shell prompt function to display signal information. ```fish function fish_prompt echo -n (fish_status_to_signal $pipestatus | string join '|') (prompt_pwd) '$ ' end ``` -------------------------------- ### Start Fish Shell Source: https://fishshell.com/docs/current/tutorial.html Type 'fish' in your current shell to launch the Fish shell. This is the initial prompt you will see. ```fish > fish Welcome to fish, the friendly interactive shell Type help for instructions on how to use fish you@hostname ~> ``` -------------------------------- ### Basic 'begin' and 'end' block Source: https://fishshell.com/docs/current/cmds/end.html Demonstrates the basic usage of 'begin' to start a command block and 'end' to terminate it. ```fish begin echo "Inside the block" end ``` -------------------------------- ### Optional Argument Example Source: https://fishshell.com/docs/current/cmds/argparse.html Provides an example of using an option with an optional argument, where the argument is directly attached to the flag. This is common for commands like 'grep'. ```fish grep --color auto # Here "auto" will be used as the search string, ``` -------------------------------- ### Build HTML Documentation with Sphinx-Build Source: https://fishshell.com/docs/current/contributing.html Build HTML documentation directly with `sphinx-build`, allowing you to specify the output directory. This example outputs to `/tmp/fish-doc`. ```bash sphinx-build -j auto -b html doc_src/ /tmp/fish-doc/ COPY ``` -------------------------------- ### Run Basic Command Source: https://fishshell.com/docs/current/tutorial.html Execute commands by typing the command name followed by its arguments, separated by spaces. This example shows the 'echo' command. ```fish > echo hello world hello world ``` -------------------------------- ### Example Fish Prompt with Informative Status Source: https://fishshell.com/docs/current/cmds/fish_hg_prompt.html An example of a fish_prompt function that enables informative Mercurial status and displays the current directory and Mercurial information. ```fish function fish_prompt ... set -g fish_prompt_hg_show_informative_status printf '%s %s$' $PWD (fish_hg_prompt) end ``` -------------------------------- ### Add Ruby's bin directory after Homebrew installation Source: https://fishshell.com/docs/current/cmds/fish_add_path.html A common use case is adding the binary directory of software installed via package managers like Homebrew to the PATH. ```fish > fish_add_path /usr/local/opt/ruby/bin ``` -------------------------------- ### Build and Run Unit Tests with Cargo Source: https://fishshell.com/docs/current/contributing.html Build the project using Cargo and then run all unit tests. Ensure you have Rust and Cargo installed. ```bash cargo build # Run unit tests cargo test ``` -------------------------------- ### Example: Conditional logic based on root user Source: https://fishshell.com/docs/current/cmds/fish_is_root_user.html This example demonstrates how to use fish_is_root_user within a function to execute different logic if the user is root. It's a common pattern for adapting script behavior. ```fish function example --description 'Just an example' if fish_is_root_user do_something_different end end ``` -------------------------------- ### Synopsis of fish_key_reader Source: https://fishshell.com/docs/current/cmds/fish_key_reader.html Displays the basic command structure for fish_key_reader. No specific setup is required to run this command. ```fish fish_key_reader [OPTIONS] ``` -------------------------------- ### Fish while loop example with file existence check Source: https://fishshell.com/docs/current/cmds/while.html This example demonstrates a while loop that checks for the existence of either 'foo.txt' or 'bar.txt'. It will print 'file exists' and sleep for 10 seconds at each interval, continuing as long as at least one of the files is present. ```fish while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end ``` -------------------------------- ### Example: Prevent Specific Commands from History Source: https://fishshell.com/docs/current/cmds/fish_should_add_to_history.html This example prevents immediate 'vault', 'mysql', or 'ls' commands from being stored in history. Commands starting with a space are still saved. ```fish function fish_should_add_to_history for cmd in vault mysql ls string match -qr "^$cmd" -- $argv; and return 1 end return 0 end ``` -------------------------------- ### Example of using pushd and popd Source: https://fishshell.com/docs/current/cmds/popd.html Demonstrates how to use pushd to add directories to the stack and popd to remove them, showing the changes in the working directory and directory stack. ```fish pushd /usr/src # Working directory is now /usr/src # Directory stack contains /usr/src pushd /usr/src/fish-shell # Working directory is now /usr/src/fish-shell # Directory stack contains /usr/src /usr/src/fish-shell popd # Working directory is now /usr/src # Directory stack contains /usr/src COPY ``` -------------------------------- ### Get Modification Time with `path mtime` Source: https://fishshell.com/docs/current/cmds/path.html Retrieve the last modification time of given paths in seconds since the Unix epoch. Use `--relative` to get seconds since the start of the command execution. Returns 0 if reading mtime succeeded for any path. ```fish path mtime [-z | --null-in] [-Z | --null-out] [-q | --quiet] [-R | --relative] [PATH ...] ``` ```fish >_ date +%s # This prints the current time as seconds since the epoch 1657217847 ``` ```fish >_ path mtime /etc/ 1657213796 ``` ```fish >_ path mtime -R /etc/ 4078 # So /etc/ on this system was last modified a little over an hour ago ``` ```fish # This is the same as >_ math (date +%s) - (path mtime /etc/) ``` -------------------------------- ### Synopsis of begin command Source: https://fishshell.com/docs/current/cmds/begin.html Shows the different syntaxes for the begin command. ```fish begin; [COMMANDS ...]; end { [COMMANDS ...] } ``` -------------------------------- ### Tab Completion Example Source: https://fishshell.com/docs/current/tutorial.html Demonstrates basic tab completion for a path. Pressing 'tab' attempts to complete the current word. ```shell > /pri`tab` => /private/ ``` -------------------------------- ### Profile Fish Startup Source: https://fishshell.com/docs/current/cmds/fish.html Profile fish's startup time and analyze configuration performance. ```bash fish --profile-startup /tmp/start.prof -ic exit ``` ```bash sort -nk2 /tmp/start.prof ``` -------------------------------- ### Example of pushd and popd usage Source: https://fishshell.com/docs/current/cmds/pushd.html Demonstrates how to use pushd to add directories to the stack and change the current directory, and how popd removes a directory from the stack. Shows the state of the working directory and directory stack after each operation. ```fish cd ~/dir1 pushd ~/dir2 pushd ~/dir3 # Working directory is now ~/dir3 # Directory stack contains ~/dir2 ~/dir1 pushd /tmp # Working directory is now /tmp # Directory stack contains ~/dir3 ~/dir2 ~/dir1 pushd +1 # Working directory is now ~/dir3 # Directory stack contains ~/dir2 ~/dir1 /tmp popd # Working directory is now ~/dir2 # Directory stack contains ~/dir1 /tmp ``` -------------------------------- ### Generate random number between 10 and 20 (even step) Source: https://fishshell.com/docs/current/cmds/random.html This example generates a random even number between 10 and 20 and counts down to 1. It demonstrates using `random` with start, step, and end arguments within a `seq` command. ```fish for i in (seq (random 10 2 20) -1 1) echo $i end ``` -------------------------------- ### Extract substring using negative start index Source: https://fishshell.com/docs/current/cmds/string-sub.html Use a negative `--start` index to specify the starting position relative to the end of the string. The substring will extend to the end of the string. ```fish >_ string sub --start=-2 abcde de ``` -------------------------------- ### Synopsis of commandline Source: https://fishshell.com/docs/current/cmds/commandline.html This shows the basic syntax for using the commandline command. It can take options and a command string. ```fish commandline [OPTIONS] [CMD] ``` -------------------------------- ### Invalid Fish script translation examples Source: https://fishshell.com/docs/current/contributing.html Examples of invalid syntax for marking strings for translation in Fish script. ```fish echo (_ hello) _ "goodbye" COPY ``` -------------------------------- ### Brace Expansion at Start of Compound Statement Source: https://fishshell.com/docs/current/language.html Shows that brace expansion is not performed if braces appear at the start of a compound statement. ```fish > {echo hello, && echo world} ``` -------------------------------- ### Edit PO file example Source: https://fishshell.com/docs/current/contributing.html Example of a PO file entry showing msgid (original string) and msgstr (translation). ```po msgid "%s: No suitable job\n" msgstr "" COPY ``` -------------------------------- ### isatty examples: non-terminal output Source: https://fishshell.com/docs/current/cmds/isatty.html These examples demonstrate cases where isatty should return a non-zero exit status, indicating it is not a terminal. ```fish echo | isatty isatty 9 isatty stdout > file isatty 2 2> file ``` -------------------------------- ### Home Directory Expansion with User Source: https://fishshell.com/docs/current/language.html The '~' character expands to the home directory. Prepending a username like '~root' expands to that user's home directory. ```fish ls ~/Music echo ~root ``` -------------------------------- ### Start Fish Shell Source: https://fishshell.com/docs/current/index.html Type 'fish' to start a new fish shell session. This command is used when fish is not your default shell. ```fish > fish COPY ``` -------------------------------- ### prevd command example Source: https://fishshell.com/docs/current/cmds/prevd.html Demonstrates the usage of prevd to move backward in directory history after navigating through several directories. It also shows the complementary nextd command. ```fish cd /usr/src # Working directory is now /usr/src cd /usr/src/fish-shell # Working directory is now /usr/src/fish-shell prevd # Working directory is now /usr/src nextd # Working directory is now /usr/src/fish-shell ``` -------------------------------- ### Start emacs in the background Source: https://fishshell.com/docs/current/language.html Starts the emacs text editor in the background, allowing the user to continue using the terminal. Append '&' to any command to run it in the background. ```fish emacs & ``` -------------------------------- ### Extract substring by start and length Source: https://fishshell.com/docs/current/cmds/string-sub.html Specify both `--start` and `--length` to extract a substring of a certain length beginning at a specific position. Indices are 1-based. ```fish >_ string sub -s 2 -l 2 abcde bc ``` -------------------------------- ### Configure Prompt with Disco Theme Source: https://fishshell.com/docs/current/cmds/fish_config.html Applies the 'disco' sample prompt for the current session and demonstrates how to save it to configuration files. ```fish fish_config prompt choose disco COPY ``` -------------------------------- ### Fish Shell example of break command Source: https://fishshell.com/docs/current/cmds/break.html This example demonstrates how to use the break command to exit a for loop early. It searches for a pattern in files and stops after the first match. ```fish for i in *.c if grep smurf $i echo Smurfs are present in $i break end end ``` -------------------------------- ### Basic prompt_pwd Usage Source: https://fishshell.com/docs/current/cmds/prompt_pwd.html Prints the current working directory, replacing the home directory with '~'. ```fish >_ cd ~/ >_ echo $PWD /home/alfa >_ prompt_pwd ~ ``` -------------------------------- ### Simple fish_title example Source: https://fishshell.com/docs/current/cmds/fish_title.html Sets a custom terminal title that includes the current directory (truncated) and the most recent foreground command. This example demonstrates how to use the argv variable and prompt_pwd. ```fish function fish_title set -q argv[1]; or set argv fish # Looks like ~/d/fish: git log # or /e/apt: fish echo (fish_prompt_pwd_dir_length=1 prompt_pwd): $argv; end ``` -------------------------------- ### Implement false command using return Source: https://fishshell.com/docs/current/cmds/return.html This example demonstrates how to implement a function that always fails by using 'return 1'. This is useful for creating custom commands or utility functions. ```fish function false return 1 end ``` -------------------------------- ### Print All Functions Source: https://fishshell.com/docs/current/cmds/functions.html Calling 'functions' without arguments prints the names of all defined functions, excluding those starting with an underscore. Use the -a or --all option to include functions starting with an underscore. ```fish functions ``` ```fish functions -a ``` -------------------------------- ### Build Fish Shell as a Self-Installing Binary Source: https://fishshell.com/docs/current/relnotes.html To build Fish as a self-installing binary, navigate to a clone of the Fish repository and run the 'cargo install' command. ```bash cargo install --path . ``` -------------------------------- ### Theme File Format Example Source: https://fishshell.com/docs/current/cmds/fish_config.html Illustrates the structure and syntax of a fish shell theme file, including definitions for light, dark, and unknown color variants. ```fish # name: 'My Theme' [light] # preferred_background: ffffff fish_color_normal 000000 fish_color_autosuggestion 7f7f7f fish_color_command 0000ee [dark] # preferred_background: 000000 fish_color_normal ffffff fish_color_autosuggestion 7f7f7f fish_color_command 5c5cff [unknown] fish_color_normal --reset fish_color_autosuggestion brblack fish_color_cancel -r fish_color_command --reset COPY ``` -------------------------------- ### Example: Conditional History Exclusion Based on Directory Source: https://fishshell.com/docs/current/cmds/fish_should_add_to_history.html This example prevents 'git pull' commands from being added to history specifically within the '/home/me/my-secret-project/' directory. It checks both the command and the current working directory. ```fish function fish_should_add_to_history # I don't want `git pull`s in my history when I'm in a specific repository if string match -qr '^git pull' -- "$argv" and string match -qr "^/home/me/my-secret-project/" -- (pwd -P) return 1 end return 0 end ``` -------------------------------- ### Argparse with Minimum Arguments Source: https://fishshell.com/docs/current/cmds/argparse.html Illustrates using argparse with a minimum argument requirement and a simple argument list. This example shows how to ensure at least one argument is provided. ```fish set -l argv foo argparse 'h/help' 'n/name' -- $argv argparse --min-args=1 -- $argv ``` -------------------------------- ### Exponentiation and modulo operations Source: https://fishshell.com/docs/current/cmds/math.html Shows how to perform exponentiation and modulo operations using the math command. ```fish math 2 ^ 3 math 10 % 3 ``` -------------------------------- ### Get Command Exit Status in Fish Source: https://fishshell.com/docs/current/faq.html Use the `$status` variable in fish to get the exit status of the last command, equivalent to `$?` in other shells. Commands can also be used directly as conditions in `if` statements. ```fish somecommand if test $status -eq 7 echo "That's my lucky number!" end ``` ```fish if somecommand echo "Command succeeded" else echo "Command failed" end ``` ```fish somecommand or someothercommand ``` -------------------------------- ### Run a command, stop it, and send to background Source: https://fishshell.com/docs/current/cmds/bg.html This demonstrates the typical workflow of starting a long-running command, stopping it with Ctrl-Z, and then resuming it in the background using the 'bg' command. ```fish > find / -name "*.js" >/tmp/jsfiles 2>/dev/null # oh no, this takes too long, let's press Ctrl-z! fish: Job 1, 'find / -name "*.js" >/tmp/jsfil…' has stopped > bg Send job 1 'find / -name "*.js" >/tmp/jsfiles 2>/dev/null' to background > # I can continue using this shell! > # Eventually: fish: Job 1, 'find / -name "*.js" >/tmp/jsfil…' has ended ``` -------------------------------- ### fish-shell case statement example Source: https://fishshell.com/docs/current/cmds/case.html Demonstrates how to use the case statement with a switch to classify an animal based on its name. It includes examples with specific names, multiple names in one case, and a wildcard case. ```fish switch $animal case cat echo evil case wolf dog human moose dolphin whale echo mammal case duck goose albatross echo bird case shark trout stingray echo fish # Note that the next case has a wildcard which is quoted case '*' echo I have no idea what a $animal is end ``` -------------------------------- ### Basic Color Usage with set_color Source: https://fishshell.com/docs/current/cmds/set_color.html Demonstrates setting foreground colors to red, blue, and a custom hex code, followed by printing text. Includes resetting to normal. ```fish set_color red; echo "Roses are red" set_color blue; echo "Violets are blue" set_color 62A; echo "Eggplants are dark purple" set_color normal; echo "Normal is nice" # Resets the background too ``` -------------------------------- ### Binding a key sequence to a command Source: https://fishshell.com/docs/current/cmds/bind.html This example demonstrates how to bind a specific key sequence (e.g., Alt+w) to execute a fish command. The command can be any valid fish command or a special input function. ```fish bind alt-w forward-word ``` -------------------------------- ### Bind command synopsis Source: https://fishshell.com/docs/current/cmds/bind.html This shows the various ways the bind command can be invoked, including setting bindings, listing them, and querying information about functions and keys. ```fish bind [(-M | --mode) MODE] [(-m | --sets-mode) NEW_MODE] [--preset | --user] [-s | --silent] KEYS COMMAND ... bind [(-M | --mode) MODE] [--preset] [--user] [--color WHEN] [KEYS] bind [-a | --all] [--preset] [--user] [--color WHEN] bind (-f | --function-names) bind (-K | --key-names) bind (-L | --list-modes) bind (-e | --erase) [(-M | --mode) MODE] [--preset] [--user] [-a | --all] | KEYS ... ``` -------------------------------- ### Omit Range Limits in Fish Index Expansions Source: https://fishshell.com/docs/current/relnotes.html Range limits in index range expansions like '$var[$start..$end]' can be omitted. '$start' defaults to 1 and '$end' defaults to -1 (the last item). ```fish echo $var[1..] echo $var[..-1] echo $var[..] ``` -------------------------------- ### Run Script with Initialization Command Source: https://fishshell.com/docs/current/cmds/fish.html Execute a script after sourcing another file for initialization. ```bash fish --init-cmd "source otherfile" script.fish ``` -------------------------------- ### Extract substring by negative start and end indices Source: https://fishshell.com/docs/current/cmds/string-sub.html Combine negative `--start` and `--end` indices to extract a substring relative to the end of the string. Note that `--length` is mutually exclusive with `--end`. ```fish >_ string sub -s 2 -e -1 abcde bcd ``` -------------------------------- ### Extract substring by negative start and end indices with specific range Source: https://fishshell.com/docs/current/cmds/string-sub.html Extract a substring using negative start and end indices to define a specific range within the string. The `--length` option cannot be used with `--end`. ```fish >_ string sub -s -3 -e -2 abcde c ``` -------------------------------- ### Redirecting output of a begin block Source: https://fishshell.com/docs/current/cmds/begin.html Illustrates how to redirect all output from a 'begin' block to a file. ```fish begin echo $xml_header echo $html_header if test -e $file ... end ... end > out.html ``` -------------------------------- ### Install libcxx on OS X Snow Leopard Source: https://fishshell.com/docs/current/relnotes.html Use this command to install the C++11 standard library on OS X 10.6 if you encounter the dyld error. This is necessary for fish version 2.5 and later on this specific OS version. ```shell sudo port -v install libcxx ``` -------------------------------- ### Fish Shell: Builtin Output Before Data Read Example Source: https://fishshell.com/docs/current/relnotes.html Demonstrates how builtins can now output before all data is read, making them usable for pipes where the previous command hasn't finished yet. This is a significant change for streaming data processing. ```fish string replace --all 'foo' 'bar' < file.txt ``` -------------------------------- ### Bind Key Sequence in Fish Shell Source: https://fishshell.com/docs/current/relnotes.html Shows how to bind a sequence of two keys using the new human-readable syntax in Fish shell. This example binds 'ctrl-x' followed by 'alt-c' to execute 'do something'. ```fish bind ctrl-x,alt-c 'do something' ``` -------------------------------- ### Install Package with Wildcard in Name Source: https://fishshell.com/docs/current/language.html When using commands like 'apt install' that perform their own wildcard matching, literal glob characters in arguments must be quoted to prevent fish from expanding them prematurely. This ensures the command receives the intended pattern. ```fish apt install "ncurses-*" ``` -------------------------------- ### Fish Shell Security Fix Example Source: https://fishshell.com/docs/current/relnotes.html This example demonstrates how fish uses Unicode non-characters internally for markers. Previously, these could be incorrectly outputted on command substitution, posing a minor security risk if external programs processed this output. This has been fixed. ```fish echo \UFDD2HOME ``` -------------------------------- ### isatty command synopsis Source: https://fishshell.com/docs/current/cmds/isatty.html The synopsis shows the basic usage of the isatty command. It can optionally take a file descriptor as an argument. ```fish isatty [FILE_DESCRIPTOR] ``` -------------------------------- ### Implement command alias with completions Source: https://fishshell.com/docs/current/cmds/complete.html Use the -w or --wraps option to make a command inherit all completions from another command, effectively creating an alias for completion purposes. ```fish complete -c hub -w git ``` -------------------------------- ### List all functions Source: https://fishshell.com/docs/current/cmds/functions.html Lists all functions, including those starting with an underscore. ```APIDOC ## functions -a ### Description Lists all functions, even those whose name starts with an underscore. ### Method functions ### Parameters #### Options - **-a** or **--all** - Lists all functions, even those whose name starts with an underscore. ### Request Example ``` functions -a ``` ### Response Example ``` # Displays a list of all functions, including hidden ones ``` ``` -------------------------------- ### Get function details Source: https://fishshell.com/docs/current/cmds/functions.html Reports detailed information about function definition paths and properties. ```APIDOC ## functions -D FUNCTION ### Description Reports the path name where the specified function is defined or could be autoloaded, `stdin` if the function was defined interactively or on the command line or by reading standard input, **-** if the function was created via source, and `n/a` if the function isn’t available. If the **--verbose** option is also specified then five lines are written: the path name, if the function was copied, the path name to where the function was originally defined, otherwise `autoloaded`, `not-autoloaded` or `n/a`, the line number within the file or zero if not applicable, `scope-shadowing` or `no-scope-shadowing`, and the function description. ### Method functions ### Parameters #### Options - **-D** or **--details** - Reports detailed information about the function. - **-v** or **--verbose** - Make some output more verbose. ### Request Example ``` functions -D my_function functions -D -v my_function ``` ### Response Example ``` # Example output for functions -D my_function: # /path/to/my_function.fish # Example output for functions -D -v my_function: # /path/to/my_function.fish # autoloaded # 10 # scope-shadowing # A brief description of my_function ``` ``` -------------------------------- ### Display help for the help command itself in fish Source: https://fishshell.com/docs/current/cmds/help.html To understand how to use the 'help' command, you can pass the '--help' option to it. ```fish help --help ``` -------------------------------- ### Windows .exe completion for myprog.exe Source: https://fishshell.com/docs/current/cmds/complete.html On Windows, use this syntax to specify completions that apply only to executables with the .exe extension. ```fish complete -c myprog.exe ... ``` -------------------------------- ### string sub Source: https://fishshell.com/docs/current/cmds/string.html Extracts a substring from each string argument based on start, end, or length parameters. ```APIDOC ## string sub ### Description Prints a substring of each string argument. The substring can be defined by start and end indices, or by a start index and a length. Indices are 1-based and can be negative to count from the end of the string. ### Method string sub ### Parameters #### Path Parameters - **STRING ...** (string) - Required - The string(s) to extract substrings from. #### Options - **-s, --start START** (integer) - The 1-based starting index of the substring. Defaults to 1. - **-e, --end END** (integer) - The 1-based ending index of the substring. - **-l, --length LENGTH** (integer) - The length of the substring. Mutually exclusive with --end. - **-q, --quiet** - Suppress output and only return exit status. ### Examples ``` >_ string sub --length 2 abcde ab >_ string sub -s 2 -l 2 abcde bc >_ string sub --start=-2 abcde de >_ string sub --end=3 abcde abc >_ string sub -e -1 abcde abcd >_ string sub -s 2 -e -1 abcde bcd ``` ``` -------------------------------- ### Translate PO file entry Source: https://fishshell.com/docs/current/contributing.html Example of a translated PO file entry with a Swedish translation. ```po msgid "%s: No suitable job\n" msgstr "%s: Inget passande jobb\n" COPY ``` -------------------------------- ### Build HTML Documentation with Cargo Xtask Source: https://fishshell.com/docs/current/contributing.html Use this command to build an HTML version of the documentation locally. The output will be in `target/fish-docs/html`. ```bash cargo xtask html-docs COPY ``` -------------------------------- ### Execute command on signal Source: https://fishshell.com/docs/current/cmds/trap.html This example demonstrates how to set up a trap to print a stack trace whenever the SIGUSR1 signal is sent to the shell. Signal names are case-insensitive and the SIG prefix is optional. ```fish trap "status --print-stack-trace" SIGUSR1 ``` -------------------------------- ### Show all completions for a command Source: https://fishshell.com/docs/current/cmds/complete.html Display all currently defined completions for a given command. ```fish complete -c git ``` -------------------------------- ### Get List Length Source: https://fishshell.com/docs/current/tutorial.html Use the `count` command to determine the number of elements in a list variable. ```fish > count $PATH 5 ``` -------------------------------- ### Join strings with a separator Source: https://fishshell.com/docs/current/cmds/string-join0.html Demonstrates joining strings with a specified separator. The `...` is used as a separator in this example. ```fish >_ seq 3 | string join ... 1...2...3 ``` -------------------------------- ### Return command synopsis Source: https://fishshell.com/docs/current/cmds/return.html This shows the basic syntax for the return command. It can optionally take an integer argument. ```fish return [N] ``` -------------------------------- ### Get the length of strings Source: https://fishshell.com/docs/current/cmds/string.html Calculates and returns the length of the provided strings. The `-q` option suppresses output. ```fish string length [-q | --quiet] [STRING ...] ```