aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--home-manager/fish/default.nix155
-rw-r--r--home-manager/zsh/default.nix127
-rw-r--r--modules/common/users/default.nix5
3 files changed, 167 insertions, 120 deletions
diff --git a/home-manager/fish/default.nix b/home-manager/fish/default.nix
new file mode 100644
index 0000000..93fd234
--- /dev/null
+++ b/home-manager/fish/default.nix
@@ -0,0 +1,155 @@
+{
+ programs ={
+ fish = {
+ enable = true;
+ generateCompletions = true;
+
+ interactiveShellInit = ''
+ set fish_greeting # Disable greeting
+ atuin init fish | source
+
+ complete -c nixos -f
+
+ complete -c nixos \
+ -n "__fish_use_subcommand" \
+ -a "update" \
+ -d "Update system using nh"
+
+ complete -c nixos \
+ -n "__fish_use_subcommand" \
+ -a "upgrade" \
+ -d "Upgrade system using nh"
+
+ complete -c nixos \
+ -n "__fish_use_subcommand" \
+ -a "config" \
+ -d "Edit nix config file"
+
+ complete -c nixos \
+ -n "__fish_use_subcommand" \
+ -a "clean" \
+ -d "Clean nix store"
+
+ complete -c nixos \
+ -n "__fish_seen_subcommand_from config" \
+ -a "(__fish_nixos_config_files)" \
+ -f
+ '';
+
+ shellAliases = {
+ ls = "eza --icons=always --color=always";
+ ll = "eza -a --long --icons=always --color=always --no-time";
+ lt = "eza -a --long --tree --icons=always --color=always --no-time";
+
+ cat = "bat";
+
+ grep = "grep --color=auto";
+
+ mv = "mv -i";
+ cp = "cp -i";
+ rm = "rm -i";
+
+ fetch = "fastfetch -c examples/7";
+ };
+ shellInitLast = ''
+ atuin init fish | source
+ eval "$(starship init fish)"
+ '';
+
+ functions = {
+ __fish_nixos_config_files = ''
+ # Only show directories and files inside ~/.nix
+ set base "$HOME/.nix"
+
+ for f in (command find $base \
+ \( -type d -name .git -prune \) -o \
+ -type f -print 2>/dev/null)
+
+ if string match -rq '\.(otf|ttf|svg|png|jpg)$' -- $f
+ continue
+ end
+ echo $f
+ end | while read -l f
+ set rel (string replace -r "^$base/" "" $f)
+ echo $rel
+ end
+ '';
+
+ nixos = ''
+ set defaultResponse "Usage: nixos update | up || nixos upgrade || nixos config <path> || nixos clean"
+ if test (count $argv) -lt 1
+ echo defaultResponse
+ return 1
+ end
+
+ switch $argv[1]
+ case update up
+ if test (count $argv) -gt 1
+ echo "Error: 'nixos update' takes no additional arguments."
+ return 1
+ end
+ nh os switch $HOME/.nix
+ case upgrade
+ if test (count $argv) -gt 1
+ echo "Error: 'nixos upgrade' takes no additional arguments."
+ return 1
+ end
+ nh os switch $HOME/.nix -u --ask
+ case config
+ if test (count $argv) -lt 2
+ echo "Error: 'nixos config' requires a <path> argument (relative to $HOME/.nix)"
+ return 1
+ end
+ hx ~/.nix/$argv[2]
+ case clean
+ if test (count $argv) -gt 1
+ echo "Error: 'nixos clean' takes no additional arguments."
+ return 1
+ end
+ nh clean --verbose
+ case '*'
+ echo defaultResponse
+ return 1
+ end
+ '';
+
+ nix = ''
+ if test $argv[1] = develop
+ set -l flake
+ if test (count $argv) -lt 2
+ echo "Usage: nix develop <python|nim|js|flake> [..]"
+ return 1
+ end
+
+ switch $argv[2]
+ case python
+ set flake $HOME/.nix#python
+ set argv $argv[3..-1]
+ case js
+ set flake $HOME/.nix#js
+ set argv $argv[3..-1]
+ case python
+ set flake $HOME/.nix#nim
+ set argv $argv[3..-1]
+ case '*'
+ set flake $argv[2]
+ set argv $argv[3..-1]
+ end
+ command nix develop $flake -c fish
+ else
+ command nix $argv
+ end
+ '';
+ };
+ };
+
+ starship = {
+ enable = true;
+ };
+
+ atuin = {
+ enable = true;
+ enableFishIntegration = true;
+ };
+ };
+}
diff --git a/home-manager/zsh/default.nix b/home-manager/zsh/default.nix
index d713873..400d11e 100644
--- a/home-manager/zsh/default.nix
+++ b/home-manager/zsh/default.nix
@@ -1,125 +1,14 @@
-{ config, pkgs, lib, ... }: let
- nixosScript = ''
- nixos() {
- case $1 in
- update | up)
- if [ "$#" -gt 1 ]; then
- echo "Error: 'nixos update' takes no additional arguments."
- return 1
- fi
- nh os switch $HOME/.nix --ask
- ;;
- upgrade)
- if [ "$#" -gt 1 ]; then
- echo "Error: 'nixos upgrade' takes no additional arguments."
- return 1
- fi
- nh os switch $HOME/.nix -u --ask
- ;;
- clean)
- nh clean all --verbose
- ;;
- config)
- hx ~/.nix/"$2"
- ;;
- *)
- echo "Usage: nixos update | up || nixos upgrade || nixos config <path>"
- ;;
- esac
- }
-
- nix() {
- if [[ $1 == "develop" ]]; then
- shift
- local flake
- case $1 in
- python)
- flake="$HOME/.nix#python"
- shift
- ;;
- nim)
- flake="$HOME/.nix#nim"
- shift
- ;;
- js)
- flake="$HOME/.nix#js"
- shift
- ;;
- *)
- flake="$1"
- shift
- ;;
- esac
- command nix develop "$flake" -c zsh
- else
- command nix "$@"
- fi
- }
-
- _nixos_autocomplete() {
- _arguments \
- '1: :->subcmd' \
- '2: :->files'
-
- case $state in
- subcmd)
- local -a commands
- commands=("update" "config")
- _describe 'command' commands
- ;;
- files)
- # Check if the subcommand is config.
- if [[ $words[2] == "config" ]]; then
- _files -W "$HOME/.nix" -g '*'
- fi
- ;;
- esac
- }
-
- compdef _nixos_autocomplete nixos
- '';
-in {
- programs.zsh = {
- enable = true;
-
- autosuggestion.enable = true;
- enableCompletion = true;
- syntaxHighlighting.enable = true;
-
- shellAliases = {
- ls = "eza --icons=always --color=always";
- ll = "eza -a --long --icons=always --color=always --no-time";
- lt = "eza -a --long --tree --icons=always --color=always --no-time";
-
- cat = "bat";
- mk = "(){ mkdir -p $1 && cd $1 }";
-
- grep = "grep --color=auto";
-
- mv = "mv -i";
- cp = "cp -i";
- rm = "rm -i";
-
- fetch = "fastfetch -c examples/7";
-
- nix-shell = "nix-shell --run $SHELL";
- };
-
- initContent = ''
- ${nixosScript};
- eval "$(atuin init zsh)"
- eval "$(starship init zsh)"
- '';
- };
-
+{
programs = {
- starship = {
+ zsh = {
enable = true;
- };
- atuin = {
- enable = true;
- enableZshIntegration = true;
+ initExtra = ''
+ if [[ $(ps -o command= -p "$PPID" | awk '{print $1}') != 'fish' ]]
+ then
+ exec fish -l
+ fi
+ '';
};
};
}
diff --git a/modules/common/users/default.nix b/modules/common/users/default.nix
index 3dfcbfa..460fb8a 100644
--- a/modules/common/users/default.nix
+++ b/modules/common/users/default.nix
@@ -21,5 +21,8 @@
};
};
- programs.zsh.enable = true;
+ programs = {
+ zsh.enable = true;
+ fish.enable = true;
+ };
}
Directive (EU) 2019/790, Article 4(3); all rights regarding Text and Data Mining (TDM) are reserved.