Skip to content

Commit

Permalink
group aliases
Browse files Browse the repository at this point in the history
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
[skip ci]
  • Loading branch information
phanirithvij committed Dec 9, 2024
1 parent 18932d2 commit 93b74ca
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 35 deletions.
7 changes: 6 additions & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ more are in my zet but that is yet to be made public

## TODO

- [ ] wrapper-manager
- [x] wrapper-manager
- [x] duf with aliases
- i.e. a package provides its own aliases
- [x] it is possible in home-manager but what about wrapm
- I don't think it is possible, wrapm wraps programs nothing to do with shell config
- implemented a basic abstraction which provides `programs.<name>-aliases.enable`
- [ ] auto gen statix, dprint config
- like pre-commit-config.yml by git-hooks.nix
- [ ] npins with flake inputs
Expand Down
5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
flake-inputs = inputs;
};

hmAliasModules = (import ./home/applications/special.nix { inherit pkgs; }).aliasModules;
homeConfig =
{
username,
Expand All @@ -179,7 +180,7 @@
}:
home-manager.lib.homeManagerConfiguration {
pkgs = pkgs';
modules = [ ./home/${username} ] ++ modules;
modules = [ ./home/${username} ] ++ modules ++ hmAliasModules;
# TODO sharedModules sops
extraSpecialArgs = {
flake-inputs = inputs;
Expand Down Expand Up @@ -296,7 +297,7 @@
username = "nixos";
hostname = "nixos";
};
sharedModules = common-hm-modules;
sharedModules = common-hm-modules ++ hmAliasModules;
};
}
./hosts/nixos/iso.nix
Expand Down
32 changes: 1 addition & 31 deletions home/applications/shells/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@

shellAliases = {
cat = "bat";
l = "ls";
l1 = "llb";
l2 = "llab";
llb = "eza --long --header --icons --git -B";
llab = "eza --long --header --icons --git --all -B";
llh = "eza --long --header --icons --git";
llS = "eza --long --header --icons --git -B -s size";
llSh = "eza --long --header --icons --git -s size";
opop = "xdg-open";
lac = "lazyconf";
laz = "lazygit";
Expand All @@ -78,10 +70,6 @@
vim = "nvim";
n = "v";

t = "tmux";
ta = "tmux a";
at = "tmux a";
tma = "tmux a";
#tag = "tmsu";

tmpsize = "sudo mount -o remount,size=8589934592 /tmp";
Expand All @@ -93,30 +81,12 @@
sport = "sudo lsof -i -P -n | rg LISTEN";
wport = "viddy --disable_auto_save -p -d -n 0.2 netstat -tuplen";
wports = "sudo viddy --disable_auto_save -p -d -n 0.2 netstat -tuplen";
dufw = "CLICOLOR_FORCE=1 COLORTERM='truecolor' viddy --disable_auto_save -p -d -n 0.5 duf";
wduf = "CLICOLOR_FORCE=1 COLORTERM='truecolor' viddy --disable_auto_save -p -d -n 0.5 duf";
dufi = ''
viddy --disable_auto_save -p -d -n 0.5 '
CLICOLOR_FORCE=1 COLORTERM="truecolor" duf \
-only local,fuse -hide-mp /boot/efi \
-output "mountpoint, avail, usage, inodes_avail, inodes_usage, filesystem" -sort usage;
echo /;
btrfs fi df /;
echo ----------;
echo /shed;
btrfs fi df /shed;
'
'';
dfah = ''viddy --disable_auto_save -p -n 0.1 "df --output=source,iavail,ipcent,avail,pcent,target -h | (sed -u 1q; sort -h -r -k 4) # Sort by Avail"'';
dffh = ''viddy --disable_auto_save -p -n 0.1 "df --output=source,iavail,ipcent,avail,pcent,target -h | (sed -u 1q; sort -h -r -k 5) # Sort by Use%"'';
dfao = ''viddy --disable_auto_save -p -n 0.1 "df --output=source,iavail,ipcent,avail,pcent,target | (sed -u 1q; sort -h -r -k 4) # Sort by Avail"'';
dffo = ''viddy --disable_auto_save -p -n 0.1 "df --output=source,iavail,ipcent,avail,pcent,target | (sed -u 1q; sort -h -r -k 5) # Sort by Use%"'';

prog = "viddy --disable_auto_save -p -n 0.5 progress -w";
wls = "viddy --disable_auto_save -p -d -n 0.1 exa --long --header --icons -B --color=always";
wlsa = "viddy --disable_auto_save -p -t -d -n 0.1 exa --long --header --icons -B --all --color=always";
wll = "viddy --disable_auto_save -p -d -n 0.1 exa --long --header --icons --git -B --color=always";
wlla = "viddy --disable_auto_save -p -t -d -n 0.1 exa --long --header --icons --git -B --all --color=always";
wpactl = ''viddy --disable_auto_save "pactl list | rg -U \".*bluez_card(.*\n)*\""'';
mem = ''
viddy -n 0.5 -d --disable_auto_save '
Expand All @@ -132,7 +102,7 @@
nixfire = "nixGL firefox & disown;tmux splitw;exit";
f = "firefox & disown;tmux splitw;exit";
firefox = "firefox & disown;tmux splitw;exit";
tor = "~/Desktop/tor.desktop & disown;tmux splitw;exit";
tor = "tor-browser & disown;tmux splitw;exit";
zoom = "zoom & disown;tmux splitw;exit";
telegram = "telegram-desktop & disown;tmux splitw;exit";
discord = "discord & disown;tmux splitw;exit";
Expand Down
5 changes: 5 additions & 0 deletions home/applications/shells/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
};
};
programs.bat.enable = true;

programs.eza.enable = true;
programs.eza-aliases.enable = true;

programs.duf-aliases.enable = true;

programs.fd = {
enable = true;
package = pkgs.fd;
Expand Down
65 changes: 65 additions & 0 deletions home/applications/special.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Provides a way to group a command and custom aliases together
# allows to turn off custom defined aliases per package
# but original aliases by home-manager programs.<name>.enableAliases etc. are unaffected
{
pkgs,
}:
let
hm-lib = import ../../lib/hm;
inherit (hm-lib) mkAliasModule;
mkAliasModule' =
pkg: aliases:
mkAliasModule {
inherit (pkgs) lib;
inherit pkg aliases;
};
in
rec {
# pkg, aliases
# pkg -> programs."${lib.getName pkg}-aliases"
groups = [
[
pkgs.duf
{
dufw = "CLICOLOR_FORCE=1 COLORTERM='truecolor' viddy --disable_auto_save -p -d -n 0.5 duf";
wduf = "CLICOLOR_FORCE=1 COLORTERM='truecolor' viddy --disable_auto_save -p -d -n 0.5 duf";
dufi = ''
viddy --disable_auto_save -p -d -n 0.5 '
CLICOLOR_FORCE=1 COLORTERM="truecolor" duf \
-only local,fuse -hide-mp /boot/efi \
-output "mountpoint, avail, usage, inodes_avail, inodes_usage, filesystem" -sort usage;
echo /;
btrfs fi df /;
'
'';
}
]
[
pkgs.eza
{
l = "ls";
l1 = "llb";
l2 = "llab";
llb = "eza --long --header --icons --git -B";
llab = "eza --long --header --icons --git --all -B";
llh = "eza --long --header --icons --git";
llS = "eza --long --header --icons --git -B -s size";
llSh = "eza --long --header --icons --git -s size";
wls = "viddy --disable_auto_save -p -d -n 0.1 eza --long --header --icons -B --color=always";
wlsa = "viddy --disable_auto_save -p -t -d -n 0.1 eza --long --header --icons -B --all --color=always";
wll = "viddy --disable_auto_save -p -d -n 0.1 eza --long --header --icons --git -B --color=always";
wlla = "viddy --disable_auto_save -p -t -d -n 0.1 eza --long --header --icons --git -B --all --color=always";
}
]
[
pkgs.wrappedPkgs.tmux
{
t = "tmux";
ta = "tmux a";
at = "tmux a";
tma = "tmux a";
}
]
];
aliasModules = map (a: mkAliasModule' (builtins.elemAt a 0) (builtins.elemAt a 1)) groups;
}
12 changes: 12 additions & 0 deletions home/applications/tmux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
enable = true;
package = pkgs.wrappedPkgs.tmux;
};
programs.tmux-aliases.enable = true;

/*
TODO when I know more about nix
aliases.tmux = {
pkg = pkgs.wrappedPkgs.tmux;
t = "tmux";
ta = "tmux a";
at = "tmux a";
tma = "tmux a";
};
*/

home.packages = [ pkgs.sesh ];
# tmuxp
Expand Down
4 changes: 3 additions & 1 deletion home/rithviz/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{ pkgs, ... }:

# TODO generalise this, test this in a vm
# this host is dead, deleted

# rust
# delta exa bat fd ripgrep sd starship du-dust

Expand Down Expand Up @@ -31,7 +34,6 @@
home.packages = with pkgs; [
air # reload go run
babelfish # bash to fish
btop # fancy process manager like htop
cmatrix # screensaver
difftastic # fancy diff
duf # fancy du
Expand Down
3 changes: 3 additions & 0 deletions lib/hm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
mkAliasModule = import ./hm-mkalias-module.nix;
}
42 changes: 42 additions & 0 deletions lib/hm/hm-mkalias-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
aliases ? [ ],
lib,
name ? lib.getName pkg,
pkg,
}:
{
config,
options,
lib,
...
}:

let
cfg = config.programs."${name}-aliases";
inherit aliases;
inherit (lib)
mkIf
mkMerge
mkEnableOption
;
in
{
# avoid enableAliases, e.g. eza errors with deprecated
options.programs."${name}-aliases" = {
enable = mkEnableOption "${name} aliases grouped";
};

config = mkIf cfg.enable {
programs.bash.shellAliases = aliases;
programs.fish = mkMerge [
(mkIf (!config.programs.fish.preferAbbrs) {
shellAliases = aliases;
})
(mkIf config.programs.fish.preferAbbrs {
shellAbbrs = aliases;
})
];
programs.zsh.shellAliases = aliases;
# TODO nushell ion etc
};
}

0 comments on commit 93b74ca

Please sign in to comment.