From f15ecafe499d99a9a7f5727d982e9ce59854e13a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 28 Feb 2025 18:08:27 +0100 Subject: [PATCH] shell --- .../pbsds/home/profiles/bashrc.d/nix-shell.sh | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/users/pbsds/home/profiles/bashrc.d/nix-shell.sh b/users/pbsds/home/profiles/bashrc.d/nix-shell.sh index e515fa1..690894f 100644 --- a/users/pbsds/home/profiles/bashrc.d/nix-shell.sh +++ b/users/pbsds/home/profiles/bashrc.d/nix-shell.sh @@ -1,14 +1,40 @@ -function ns() { +_ns() { + local is_dev=$1; shift # "true" or "false" local args=() + if $is_dev; then + local arg_suffix="^*" + else + local arg_suffix="" + fi for pkg in "$@"; do + if [[ "$pkg" = -- ]]; then + break + fi if [[ "$pkg" =~ ^.*[#:/].*$ ]]; then - args+=("$pkg") + args+=("${pkg}${arg_suffix}") else - args+=(nixpkgs#"$pkg") + args+=(nixpkgs#"${pkg}${arg_suffix}") fi done - >&2 echo + exec nix shell "${args[@]}" + # Run anything after -- as a command + local cmd=("$@") + while [[ "${#cmd[@]}" -gt 2 && ${cmd[0]} != "--" ]]; do + cmd=("${cmd[@]:1}") + done + cmd=("${cmd[@]:1}") + if [[ ${#cmd[@]} -gt 0 ]]; then + ( + _ns false "$args" + set -x + "${cmd[@]}" + ) + return $? + fi + + >&2 echo -n + + >&2 printf " %q" exec nix shell "${args[@]}" + >&2 echo local outpaths="$( export NIXPKGS_ALLOW_BROKEN export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM @@ -74,7 +100,6 @@ function ns() { export PATH="$(IFS=: ; printf "%s" "${add_to_path[*]}")${PATH:+":$PATH"}" fi if [[ "${#add_to_libs[@]}" -gt 0 ]]; then - export NIX_LDFLAGS="$(IFS=" " ; printf "-L%s" "${add_to_libs[*]}")${NIX_LDFLAGS:+" $NIX_LDFLAGS"}" export LD_LIBRARY_PATH="$(IFS=: ; printf "%s" "${add_to_libs[*]}")${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"}" fi if [[ "${#add_to_share[@]}" -gt 0 ]]; then @@ -82,9 +107,13 @@ function ns() { fi if [[ "${#add_to_include[@]}" -gt 0 ]]; then export CPATH="$(IFS=: ; printf "%s" "${add_to_include[*]}")${CPATH:+":$CPATH"}" + export CMAKE_INCLUDE_PATH="$(IFS=: ; printf "%s" "${add_to_include[*]}")${CMAKE_INCLUDE_PATH:+":$CMAKE_INCLUDE_PATH"}" fi if [[ "${#add_to_pythonpath[@]}" -gt 0 ]]; then export PYTHONPATH="$(IFS=: ; printf "%s" "${add_to_pythonpath[*]}")${PYTHONPATH:+":$PYTHONPATH"}" # export PYTHONNOUSERSITE=1 fi } + +ns() { _ns false "$@"; } +nd() { _ns true "$@"; }