brunogama / fish-functions

Useful fish functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Config and functions for the Fish Shell, making common tasks more convenient.


# Backup your old ~/.config/fish first, then:
$ git clone ~/.config/fish


File Manipulation

backup <file> (source)

Creates a copy of file as file.bak.

$ ls
$ backup
$ ls

Recommended abbreviation: abbr -a bk backup

restore <backup> (source)

Rename a backup such as file.bak to remove the .bak extension.

$ ls
$ restore
$ ls

Recommended abbreviation: abbr -a re restore

mkdir-cd <directory> (source)

Make a directory and cd into it.

$ mkdir-cd folder
folder $

Recommended abbreviation: abbr -a mc mkdir-cd

copy <source> ... [<destination>] (source)

cp with some extra behaviors.

Automatic recursive copy for directories. Rather than only copying the files from a directory, copies the directory itself.


$ mkdir testdir
$ touch testdir/file.txt
$ mkdir destdir
# Standard cp needs -r flag
$ cp testdir/ destdir/
cp: testdir/ is a directory (not copied).
# And does not preserve the source folder
$ cp -r testdir/ destdir/
$ ls destdir/
# Cleaning up...
$ rm destdir/file.txt
# In contrast, using `copy` function:
$ copy testdir/ destdir/
$ ls destdir/

Recommended abbreviation: abbr -a cp copy. If you do this abbreviation, use command cp for the low-level cp.

remove <target> (source)

rm with an extra behavior.

If removing a directory with write-protected .git, confirm once to ensure the git directory is desired to be removed.

$ ls -a dodo
.  ..  .git  x
$ remove dodo
Remove .git directory dodo/.git?> y

Using plain rm:

$ rm -r dodo
override r--r--r--  razzi/staff for dodo/.git/objects/58/05b676e247eb9a8046ad0c4d249cd2fb2513df? y
override r--r--r--  razzi/staff for dodo/.git/objects/f3/7f81fa1f16e78ac451e2d9ce42eab8933bd99f? y
override r--r--r--  razzi/staff for dodo/.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391? ^C
$ rm -rf dodo

Recommended abbreviation: abbr -a rm remove. If you do this abbreviation, use command rm for the low-level rm.

clean-unzip <zipfile> (source)

Unzips a .zip archive without polluting the current directory, by creating a directory even if the zipfile does not have a folder level.

unzip-cd <zipfile> (source)

Unzip a zip directory and cd into it. Uses clean-unzip to create a folder if the zipfile doesn't have one.

$ unzip-cd
 extracting: out/a.txt
 extracting: out/b.txt
files $ ls
a.txt  b.txt

Text Utilities

coln <number> (source)

Splits input on whitespace and prints the column indicated.

$ echo 1 2 | coln 2

row <number> (source)

Prints the row of input indicated.

$ seq 3 | row 2

skip-lines <number> (source)

Skips the first n lines of stdin.

$ seq 5 | skip-lines 2

take <n> (source)

Take the first n lines of standard input.

$ seq 5 | take 3

word-count (source)

Count the words from standard input. Like wc -w but does not put spaces around the number.

$ echo a b | word-count
# Compare to:
$ echo a b | wc -w

line-count (source)

Count the lines from standard input. Like wc -l but does not put spaces around the number.

$ seq 3 | line-count
# Compare to:
$ seq 3 | wc -l

char-count (source)

Count the characters from standard input. Like wc -c but does not put spaces around the number.

$ echo -n a b | char-count
# Compare to:
$ echo -n a b | wc -c

fish utilities

string-empty <value> (source)

Test if the value is the empty string.

$ string-empty ''
$ echo $status

file-exists <file> (source)

Test if $file exists.

any-arguments <argv> (source)

Check if any arguments were passed to a fish function.

$ function something
    if any-arguments $argv
        echo Arguments were passed
        echo No arguments passed
$ something
No arguments passed
$ something 1
Arguments were passed

funcsave-last (source)

Save the last-edited fish function.

$ function hi
  echo hi
$ funcsave-last
Saved hi

Recommended abbreviation: abbr -a fs funcsave-last.

confirm (source)

Prompts the user for confirmation. Exit with status according to whether they answered y, Y, yes, or YES.

Environment Utilities

echo-variable <variable> (source)

Like echo, but without the $ or capitalization.

$ echo-variable user
$ echo $USER

Recommended abbreviation: abbr -a ev echo-variable.

Completion: completes environment variable names.

readpass <name> (source)

Prompt for a password. Does not echo entered characters.

$ readpass email
$ echo $email

symlink utilities

symlink <from> <to> (source)

Create a symbolic link, using absolute paths.

~/dotfiles $ symlink .prettierrc ~
~/dotfiles $ cat ~/.prettierrc
singleQuote: true
semi: false

Without using absolute paths:

~/dotfiles $ ln -s .prettierrc ~
~/dotfiles $ cat ~/.prettierrc
cat: /Users/razzi/.prettierrc: Too many levels of symbolic links

unsymlink <file> (source)

Removes a symlink. Errors if the file is not a symlink.

symlinks [<dir>] (source)

Lists symlinks in the given directory, or the current directory if none is passed.

link-rc [<file>] (source)

Creates a symlink from $file to the home directory (~).

git utilities

clone-cd url [destination] (source)

Clones a git repository into the current directory or the $destination if given, and cds into it. Clones with depth 1 for speed.

wip [message] (source)

Adds untracked changes and commits them with a WIP message. Additional arguments are added to the WIP message.

I use this instead of git stash so that changes are associated with the branch they're on, and the commit is tracked in the reflog.

$ git stat
## master
$ git switch -c testing
$ wip failing tests
[testing 0078f7f] WIP failing tests
$ git switch -

git-add [paths] (source)

Like git add, but defaults to . if no arguments given, rather than erroring.

Recommended abbreviation: abbr -a ga git-add

git-commit [message] (source)

Like git commit -m without the need to quote the commit message.

If no commit message is given and there's only 1 file changed, commit "(Add / Update / Delete) (that file)".

$ git-commit
[master c77868d] Update
 1 file changed, 57 insertions(+), 18 deletions(-)
$ git reset @^
Unstaged changes after reset:
$ git-add
$ git-commit Fix typo in
[master 0078f7f] Fix typo in
1 file changed, 57 insertions(+), 18 deletions(-)

Recommended abbreviation: abbr -a gc git-commit

git-add-commit [message] (source)

Combines git add -u with git-commit.

$ git status -s
$ git-add-commit Add installation instructions
[master c77868d] Add installation instructions
 1 file changed, 57 insertions(+), 18 deletions(-)

Recommended abbreviation: abbr -a gac git-add-commit.

Postgres Utilities

ensuredb <name> (source)

Ensure that a fresh database by the name given is created. Drops a database by that name if it exists, clearing database connections as necessary.

renamedb <from> <to> (source)

Renames a database.

Date Utilities

isodate (source)

Prints the date in ISO format.

$ isodate

MacOS Utilities

move-last-download (source)

Move the latest download to the current directory.

Recommended abbreviation: abbr -a mvl move-last-download.

wifi-network-name (source)

Prints the current wifi network name.

wifi-password (source)

Prints the current wifi network password.

wifi-reset (source)

Turns the wifi off and on again.

ezoic increase your site revenue


Useful fish functions


Language:Shell 99.8%Language:Python 0.2%