Update apt-description to use apt-mark for package names without ...:amd64
Functions for the Fish Shell, making common tasks more convenient.
# Backup your old ~/.config/fish first, then: $ git clone https://git.sr.ht/~razzi/fish-functions ~/.config/fish
In previous versions, other fish config including abbrs were included as well. That changed much more frequently than the functions, so I split them out.
Now they are at https://git.sr.ht/~razzi/dotfiles (see that repository's README for isntallation instructions).
Creates a copy of
$ ls README.md $ backup README.md $ ls README.md README.md.bak
abbr -a bk backup
Rename a backup such as
file.bak to remove the
$ ls README.md README.md.bak $ restore README.md.bak $ ls README.md
abbr -a re restore
Make a directory and cd into it.
$ mkdir-cd folder folder $
abbr -a mc mkdir-cd
cp with some extra behaviors.
Automatic recursive copy for directories. Rather than only copying the files from a directory, copies the directory itself.
Also uses -i flag by default, which will warn you if a copy would overwrite a destination file.
$ 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/ file.txt # Cleaning up... $ rm destdir/file.txt # In contrast, using `copy` function: $ copy testdir/ destdir/ $ ls destdir/ testdir
abbr -a cp copy. If you do this abbreviation, use
command cp for the low-level
Creates a file, including parent directories as necessary.
$ create-file a/b/c $ tree . └── a └── b └── c
Moves a directory's contents to the current directory and removes the empty directory.
$ tree . └── a └── b └── c $ eat a $ tree . └── b └── c
If a file in the current directory would be overwritten by
eat, it will give an error and exit with status 1.
An illustration of this:
$ tree . ├── dir-a │ └── dir-b │ ├── some_file │ └── some_other_file └── dir-b └── would_be_overwritten 3 directories, 3 files $ eat dir-a eat: file would be overwritten: ./dir-b
Uses -i flag by default, which will warn you if
mv would overwrite a destination file.
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
$ 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
abbr -a rm remove. If you do this abbreviation, use
command rm for the low-level
Move the latest download to destination directory, which is the current directory if none is specified..
abbr -a mvl move-last-download.
.zip archive without polluting the current directory, by creating a
directory even if the zipfile does not have a folder level.
Unzip a zip directory and cd into it. Uses
clean-unzip to create a folder if
the zipfile doesn't have one.
$ unzip-cd files.zip Archive: files.zip extracting: out/a.txt extracting: out/b.txt files $ ls a.txt b.txt
Splits input on whitespace and prints the column indicated.
$ echo 1 2 | coln 2 2
Prints the row of input indicated.
$ seq 3 | row 2 2
Skips the first n lines of stdin.
$ seq 5 | skip-lines 2 3 4 5
Take the first
n lines of standard input.
$ seq 5 | take 3 1 2 3
Count the words from standard input. Like
wc -w but does not put spaces around the number.
$ echo a b | word-count 2 # Compare to: $ echo a b | wc -w 2
Count the lines from standard input. Like
wc -l but does not put spaces around the number.
$ seq 3 | line-count 3 # Compare to: $ seq 3 | wc -l 3
Count the characters from standard input. Like
wc -c but does not put spaces around the number.
$ echo -n a b | char-count 3 # Compare to: $ echo -n a b | wc -c 3
Test if the value is the empty string.
$ string-empty '' $ echo $status 0
If you use this on a variable, be sure to use the variable's value using
$ if string-empty $VIRTUAL_ENV echo in venv end
string-empty VIRTUAL_ENV will always return
Check if if
$path is a directory.
Check if any arguments were passed to a fish function.
$ function something if any-arguments $argv echo Arguments were passed else echo No arguments passed end end $ something No arguments passed $ something 1 Arguments were passed
Save the last-edited
$ function hi echo hi end $ funcsave-last Saved hi
abbr -a fs funcsave-last.
Prompts the user for confirmation. Exit with status according to whether they answered
Just the current directory name, please.
mydir $ curdir mydir
You probably won't need this interactively since the current directory is usually part of your
but this is useful for scripting.
echo, but without the
$ or capitalization.
$ echo-variable user razzi $ echo $USER razzi
abbr -a ev echo-variable.
Completion: completes environment variable names.
Prompt for a password. Does not echo entered characters.
$ readpass email ●●●●●●●●●●●●●●●●● $ echo $email firstname.lastname@example.org
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
Remove a symlink. Errors if the file is not a symlink.
List symlinks in the given directory, or the current directory if none is passed.
Create a symlink from
$file to the home directory (
git repository into the current directory (or the optional
cd into it. Clones with depth 1 for speed.
If a folder by that name already exists, great, you probably already cloned it, just cd into the directory and pull.
If it's trying to clone into a non-empty directory, make a new folder in that directory with the repository name and clone into that, instead of erroring.
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 M tests.py $ git switch -c testing $ wip failing tests [testing 0078f7f] WIP failing tests $ git switch -
git add, but defaults to
. if no arguments given, rather than erroring.
... to mean
../... If you need more levels of
../.. I guess they could be added.
Did I mention I have a function called
cds up 2 levels?
abbr -a ga git-add
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 README.md 1 file changed, 57 insertions(+), 18 deletions(-) $ git reset @^ Unstaged changes after reset: M README.md $ git-add $ git-commit Fix typo in README.md [master 0078f7f] Fix typo in README.md 1 file changed, 57 insertions(+), 18 deletions(-)
abbr -a gc git-commit
Add a pattern to the
abbr -a giti gitignore.
Install a vim plugin using the builtin vim plugin mechanism.
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.
Renames a database.
Prints the date in ISO format.
$ isodate 2020-01-28
Prints the current wifi network name.
Prints the current wifi network password.
Turns the wifi off and on again.