about summary refs log tree commit diff
path: root/fish/functions.fish
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-06T14·54+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-17T10·56+0000
commit7175d230c2cb2e5d90a25bcbd012ed75eaa96860 (patch)
treeb4cad1f5b33e0b7be9b8bb77eaf8dfe5d5dcd506 /fish/functions.fish
parent73e988c29818dfb679e26d08aded8816b2e2f37c (diff)
Nixify fish configuration
This isn't 100% usable, but it works. You can build it with `nix-env` and then
run it with `wpcarros-fish`.
Diffstat (limited to 'fish/functions.fish')
-rw-r--r--fish/functions.fish65
1 files changed, 65 insertions, 0 deletions
diff --git a/fish/functions.fish b/fish/functions.fish
new file mode 100644
index 000000000000..d7e320c9a6f5
--- /dev/null
+++ b/fish/functions.fish
@@ -0,0 +1,65 @@
+# TODO: Consider a `rm` that behaves like this as well. Would then be useful to
+# support something like a "Trash" folder so that I can undo unintentional
+# deletions.
+function cp_dwim -d "Copy files and directories similarly."
+    # TODO: Where do I put documentation like this?
+    # Calls `cp -r` when a directory is specified, otherwise uses `cp`.
+    # This is closer to the UX you expect in GUIs when you copy-and-paste files.
+    if test -d $argv[1]
+        command cp -r $argv[1..-1]
+    else
+        command cp $argv[1..-1]
+    end
+end
+
+function mkdir_cd -d "Make a directory and `cd` into it."
+    mkdir -p $argv[1] && cd $argv[1]
+end
+
+function lt -d "Like tree, except using `exa`."
+    # Convenience wrapper around `exa --tree`.
+    # Optionally accepts a number for the max-depth and a directory to list.
+    # Usage: lt 2 ./scripts
+
+    # lt
+    if test (count $argv) -eq 0
+        exa --tree --all
+
+    else if test (count $argv) -eq 1
+        # lt 2
+        if string match --quiet --regex '^[0-9]+$' $argv[1]
+            exa --tree --all --level $argv[1]
+
+        # lt path/to/directory
+        else if test -d $argv[1]
+            exa --tree --all $argv[1]
+        end
+
+    # lt 2 path/to/directory
+    else if test (count $argv) -eq 2
+        exa --tree --all --level $argv[1] $argv[2]
+    end
+
+end
+
+function lad -d "List only the directories within a directory."
+    # TODO: Support $argv[1], which is currently broken here. See functions.zsh
+    # for a reference.
+    fd --hidden --maxdepth 1 --type d
+end
+
+function laf -d "List only the files within a directory."
+    # TODO: Support $argv[1], which is currently broken here. See functions.zsh
+    # for a reference.
+    fd --hidden --maxdepth 1 --type f
+end
+
+function lal -d "List only the links within a directory."
+    # TODO: Support $argv[1], which is currently broken here. See functions.zsh
+    # for a reference.
+    fd --hidden --maxdepth 1 --type l
+end
+
+function nix_introspect -d "Search through local nixpkgs repository."
+    rg --after-context 5 "\\b$argv[1]\\b\\s*=" (nix-instantiate --find-file nixpkgs)
+end