From b97d67044d9fca3befff40cf42bd34c71e7de54b Mon Sep 17 00:00:00 2001
From: Crony Akatsuki <crony@cronyakatsuki.xyz>
Date: Sat, 1 Feb 2025 17:50:20 +0100
Subject: [PATCH] Add zsh functions, start tmux right on start.

---
 .../home-manager/configs/zsh-functions.zsh    | 43 +++++++++++++++++++
 modules/home-manager/zsh.nix                  | 19 ++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 modules/home-manager/configs/zsh-functions.zsh

diff --git a/modules/home-manager/configs/zsh-functions.zsh b/modules/home-manager/configs/zsh-functions.zsh
new file mode 100644
index 0000000..ba39a87
--- /dev/null
+++ b/modules/home-manager/configs/zsh-functions.zsh
@@ -0,0 +1,43 @@
+#!/usr/bin/env zsh
+# Open a script in path with vim quicly
+vish () {
+    nvim $(which $1)
+}
+
+# Create a directory and change into it
+md () {
+    mkdir -p "$@" && cd "$@"
+}
+
+# Move a file and create a link in it's place
+mvln () {
+    from=$(readlink -f $1)
+    to="$2"
+    [ ! -d "$(dirname $to)" ] && mkdir -p "$(dirname $to)"
+    mv $from $to
+    ln -s $to $from
+}
+
+# nnn
+n () {
+    # Block nesting of nnn in subshells
+    [ "${NNNLVL:-0}" -eq 0 ] || {
+        echo "nnn is already running"
+        return
+    }
+
+    # Tempfile location
+    NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
+
+    nnn "$@"
+
+    [ ! -f "$NNN_TMPFILE" ] || {
+        . "$NNN_TMPFILE"
+        rm -f "$NNN_TMPFILE" > /dev/null
+    }
+}
+
+# upfast
+upfast () {
+    curl -F "file=@$(readlink -f $1)" "https://upfast.cronyakatsuki.xyz/"
+}
diff --git a/modules/home-manager/zsh.nix b/modules/home-manager/zsh.nix
index e44c8a4..42d555a 100644
--- a/modules/home-manager/zsh.nix
+++ b/modules/home-manager/zsh.nix
@@ -17,6 +17,17 @@
 
       dotDir = ".config/zsh";
 
+      shellAliases = {
+        grep = "grep --color=auto";
+        cp = "cp -iv";
+        rm = "rm -iv";
+        mkd = "mkdir -pv";
+        less = "less -R";
+        nnn = ''LC_COLLATE="C" nnn -xeaiH'';
+        df = "df -h -x devtmpfs -x tmpfs -x usbfs -x loop";
+        free = "free -mht";
+      };
+
       initExtra = ''
         # VI Mode escape timeout fix
         export KEYTIMEOUT=1
@@ -27,6 +38,10 @@
         bindkey -M vicmd 'k' history-substring-search-up
         bindkey -M vicmd 'j' history-substring-search-down
 
+        [[ -f "$HOME/.config/zsh/functions.zsh" ]] && source "$HOME/.config/zsh/functions.zsh"
+      '';
+
+      initExtraFirst = ''
         # Tmux autostart
         if [ -x "$(command -v tmux)" ] && [ -n "$DISPLAY" ] && [ -z "$TMUX" ]; then
           exec tmux new-session -A -s default >/dev/null 2>&1
@@ -46,5 +61,9 @@
         ];
       };
     };
+    # Link my functions file to ~/.config/zsh/functions.zsh
+    home.file = {
+      ".config/zsh/functions.zsh".source = ./configs/zsh-functions.zsh;
+    };
   };
 }