From b9585e5d0096ade4fce29ada99d459ecab702725 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Sat, 5 Aug 2023 00:09:50 +0900 Subject: [PATCH] Use absolute Nix paths in homemade scripts (#252) * 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 --- home-manager/fish.nix | 6 ++ home-manager/home.nix | 10 +-- home-manager/homemade.nix | 80 +++++++++++++++++++ .../share/homemade/bin/bench_shells.bash | 16 ---- home/.local/share/homemade/bin/la.bash | 5 -- home/.local/share/homemade/bin/updeps.bash | 16 ---- home/.local/share/homemade/bin/zj.bash | 7 -- 7 files changed, 88 insertions(+), 52 deletions(-) create mode 100644 home-manager/homemade.nix delete mode 100755 home/.local/share/homemade/bin/bench_shells.bash delete mode 100755 home/.local/share/homemade/bin/la.bash delete mode 100755 home/.local/share/homemade/bin/updeps.bash delete mode 100755 home/.local/share/homemade/bin/zj.bash diff --git a/home-manager/fish.nix b/home-manager/fish.nix index cb74c6e2..23358037 100644 --- a/home-manager/fish.nix +++ b/home-manager/fish.nix @@ -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 { diff --git a/home-manager/home.nix b/home-manager/home.nix index bbc62ed0..87118e6e 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -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"; @@ -52,6 +53,7 @@ }; sessionPath = [ + # See ./homemade.nix for detail "${config.xdg.dataHome}/homemade/bin" ]; }; @@ -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; } diff --git a/home-manager/homemade.nix b/home-manager/homemade.nix new file mode 100644 index 00000000..1029b3fd --- /dev/null +++ b/home-manager/homemade.nix @@ -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" + ''; + }; +} diff --git a/home/.local/share/homemade/bin/bench_shells.bash b/home/.local/share/homemade/bin/bench_shells.bash deleted file mode 100755 index fce7657b..00000000 --- a/home/.local/share/homemade/bin/bench_shells.bash +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -euxo 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 -hyperfine --warmup 1 'zsh --interactive -c exit' - -hyperfine --warmup 1 'bash -i -c exit' -hyperfine --warmup 1 'fish --interactive --command exit' diff --git a/home/.local/share/homemade/bin/la.bash b/home/.local/share/homemade/bin/la.bash deleted file mode 100755 index 47cd81fa..00000000 --- a/home/.local/share/homemade/bin/la.bash +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -exa --long --all --group-directories-first "$@" diff --git a/home/.local/share/homemade/bin/updeps.bash b/home/.local/share/homemade/bin/updeps.bash deleted file mode 100755 index 25020cd4..00000000 --- a/home/.local/share/homemade/bin/updeps.bash +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 - -rtx plugins update diff --git a/home/.local/share/homemade/bin/zj.bash b/home/.local/share/homemade/bin/zj.bash deleted file mode 100755 index 3d7f8f68..00000000 --- a/home/.local/share/homemade/bin/zj.bash +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -name="$(basename "$PWD")" - -zellij attach "$name" || zellij --session "$name"