Last active
August 6, 2025 16:27
-
-
Save naranyala/2203f889a3cb89c5cfe4599788bea915 to your computer and use it in GitHub Desktop.
the modern package manager for all linux distro, use `nix-shell -p <pkgname>`, then execute this script; for gui specific package use this script to create global shortcuts: https://gist.github.com/naranyala/312271a325d3c4fbd5fe33e07045cf7c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# chmod +x make-global-symlinks-nixpkgs.sh | |
STORE_DIR="/nix/store" | |
TARGET_DIR="/usr/bin" | |
LOG_FILE="$HOME/nix-global-symlinks.log" | |
LOG_PREFIX="\e[1;32m[LINK]\e[0m" | |
SKIP_PREFIX="\e[1;33m[SKIP]\e[0m" | |
REPLACE_PREFIX="\e[1;34m[REPLACE]\e[0m" | |
log_link() { echo -e "$LOG_PREFIX $*"; echo "[LINK] $*" >> "$LOG_FILE"; } | |
log_skip() { echo -e "$SKIP_PREFIX $*"; echo "[SKIP] $*" >> "$LOG_FILE"; } | |
log_replace() { echo -e "$REPLACE_PREFIX $*"; echo "[REPLACE] $*" >> "$LOG_FILE"; } | |
# Reset log file | |
echo "# Symlink audit — $(date)" > "$LOG_FILE" | |
echo "# Target directory: $TARGET_DIR" >> "$LOG_FILE" | |
echo >> "$LOG_FILE" | |
for pkg in "$STORE_DIR"/*; do | |
[[ -d "$pkg/bin" ]] || continue | |
for bin in "$pkg/bin/"*; do | |
[[ -x "$bin" && ! -d "$bin" ]] || continue | |
name=$(basename "$bin") | |
target="$TARGET_DIR/$name" | |
if [[ -e "$target" ]]; then | |
if [[ -L "$target" ]]; then | |
# Replace existing symlink | |
sudo ln -sf "$bin" "$target" | |
log_replace "$name → $bin (replaced existing symlink)" | |
else | |
# Skip real binaries | |
log_skip "$name is a real file in $TARGET_DIR — skipped ($bin)" | |
fi | |
else | |
# Fresh symlink | |
sudo ln -s "$bin" "$target" | |
log_link "$name → $bin" | |
fi | |
done | |
done | |
echo -e "\n\e[1;34m[INFO]\e[0m Log saved to: $LOG_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment