Skip to content

Commit

Permalink
Use absolute Nix paths in homemade scripts (#252)
Browse files Browse the repository at this point in the history
* Use absolute Nix paths in homemade scripts

* Make executable again

* Suppress noisy logging since used fullpath

* Hide conflicting fish provided la

* Add link to referenced source
  • Loading branch information
kachick authored Aug 4, 2023
1 parent 1352fda commit b9585e5
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 52 deletions.
6 changes: 6 additions & 0 deletions home-manager/fish.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
end
'';

interactiveShellInit = ''
# I define another la as a homemade scripts
# See https://stackoverflow.com/a/36700734/1212807 for using `--erase`
functions --erase la
'';

plugins = [{
name = "foreign-env";
src = pkgs.fetchFromGitHub {
Expand Down
10 changes: 2 additions & 8 deletions home-manager/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
./fish.nix
./git.nix
./darwin.nix # Omit needless parts for Linux in the file
./homemade.nix
];

home.username = lib.mkDefault "kachick";
Expand Down Expand Up @@ -52,6 +53,7 @@
};

sessionPath = [
# See ./homemade.nix for detail
"${config.xdg.dataHome}/homemade/bin"
];
};
Expand Down Expand Up @@ -152,12 +154,4 @@

# https://github.com/nix-community/home-manager/blob/master/modules/programs/rtx.nix
programs.rtx.enable = true;

# - Tiny tools by me, they may be rewritten with another language.
# - Keep *.bash in shellscript naming in this repo for maintainability, the extname should be trimmed in the symlinks
xdg.dataFile."homemade/bin/bench_shells".source = ../home/.local/share/homemade/bin/bench_shells.bash;
xdg.dataFile."homemade/bin/updeps".source = ../home/.local/share/homemade/bin/updeps.bash;
xdg.dataFile."homemade/bin/la".source = ../home/.local/share/homemade/bin/la.bash;
xdg.dataFile."homemade/bin/zj".source = ../home/.local/share/homemade/bin/zj.bash;
xdg.dataFile."homemade/bin/add_nix_channels".source = ../home/.local/share/homemade/bin/add_nix_channels.bash;
}
80 changes: 80 additions & 0 deletions home-manager/homemade.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{ pkgs, lib, ... }:

# FAQ
#
# A. How to make executable? .text= makes syms, that links to non executable file
# Q. https://github.com/nix-community/home-manager/blob/15043a65915bcc16ad207d65b202659e4988066b/modules/xsession.nix#L195C1-L197

# - Tiny tools by me, they may be rewritten with another language.
{
# - Keep *.bash in shellscript naming in this repo for maintainability, the extname should be trimmed in the symlinks
xdg.dataFile."homemade/bin/add_nix_channels".source = ../home/.local/share/homemade/bin/add_nix_channels.bash;

xdg.dataFile."homemade/bin/bench_shells" = {
executable = true;
text = ''
#!/usr/bin/env bash
set -euo pipefail
# ~ my feeling ~
# 50ms : blazing fast!
# 110ms : acceptable
# 150ms : slow
# 200ms : 1980s?
# 300ms : much slow!
# zsh should be first, because it often makes much slower with the completion
${lib.getExe pkgs.hyperfine} --warmup 1 '${lib.getExe pkgs.zsh} --interactive -c exit'
${lib.getExe pkgs.hyperfine} --warmup 1 '${lib.getExe pkgs.bashInteractive} -i -c exit'
${lib.getExe pkgs.hyperfine} --warmup 1 '${lib.getExe pkgs.fish} --interactive --command exit'
'';
};

xdg.dataFile."homemade/bin/updeps" = {
executable = true;
text = ''
#!/usr/bin/env bash
set -euo pipefail
case ''${OSTYPE} in
linux*)
sudo apt update --yes && sudo apt upgrade --yes
;;
darwin*)
softwareupdate --install --recommended
;;
esac
nix-channel --update
${lib.getExe pkgs.rtx} plugins update
'';
};

xdg.dataFile."homemade/bin/la" = {
executable = true;
text = ''
#!/usr/bin/env bash
set -euo pipefail
${lib.getExe pkgs.exa} --long --all --group-directories-first "$@"
'';
};

xdg.dataFile."homemade/bin/zj" = {
executable = true;
text = ''
#!/usr/bin/env bash
set -euo pipefail
name="$(${lib.getBin pkgs.coreutils}/bin/basename "$PWD")"
${lib.getExe pkgs.zellij} attach "$name" || ${lib.getExe pkgs.zellij} --session "$name"
'';
};
}
16 changes: 0 additions & 16 deletions home/.local/share/homemade/bin/bench_shells.bash

This file was deleted.

5 changes: 0 additions & 5 deletions home/.local/share/homemade/bin/la.bash

This file was deleted.

16 changes: 0 additions & 16 deletions home/.local/share/homemade/bin/updeps.bash

This file was deleted.

7 changes: 0 additions & 7 deletions home/.local/share/homemade/bin/zj.bash

This file was deleted.

0 comments on commit b9585e5

Please sign in to comment.