mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 05:02:10 +00:00
theme and scripts
This commit is contained in:
parent
deade2bafb
commit
7ae7c1ceec
17 changed files with 575 additions and 270 deletions
87
scripts/default.nix
Normal file
87
scripts/default.nix
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
}: let
|
||||
theme = import ../lib/theme.nix {inherit config;};
|
||||
|
||||
tmuxConfigs = {
|
||||
dark = pkgs.writeText "tmux-theme-dark.conf" (theme.renderTmux "dark");
|
||||
light = pkgs.writeText "tmux-theme-light.conf" (theme.renderTmux "light");
|
||||
};
|
||||
|
||||
mkScript = {
|
||||
file,
|
||||
name,
|
||||
runtimeInputs ? [],
|
||||
replacements ? {},
|
||||
}:
|
||||
pkgs.writeShellApplication {
|
||||
inherit name runtimeInputs;
|
||||
text =
|
||||
lib.replaceStrings
|
||||
(builtins.attrNames replacements)
|
||||
(builtins.attrValues replacements)
|
||||
(builtins.readFile file);
|
||||
};
|
||||
|
||||
packages = {
|
||||
ga = mkScript {
|
||||
name = "ga";
|
||||
file = ./ga.sh;
|
||||
runtimeInputs = with pkgs; [git];
|
||||
};
|
||||
|
||||
ghpr = mkScript {
|
||||
name = "ghpr";
|
||||
file = ./ghpr.sh;
|
||||
runtimeInputs = with pkgs; [gh git gnugrep gnused coreutils];
|
||||
};
|
||||
|
||||
gpr = mkScript {
|
||||
name = "gpr";
|
||||
file = ./gpr.sh;
|
||||
runtimeInputs = with pkgs; [gh fzf gnugrep coreutils];
|
||||
};
|
||||
|
||||
iosrun = mkScript {
|
||||
name = "iosrun";
|
||||
file = ./iosrun.sh;
|
||||
runtimeInputs = with pkgs; [findutils gnugrep coreutils];
|
||||
};
|
||||
|
||||
mdview = mkScript {
|
||||
name = "mdview";
|
||||
file = ./mdview.sh;
|
||||
};
|
||||
|
||||
ni = mkScript {
|
||||
name = "ni";
|
||||
file = ./ni.sh;
|
||||
runtimeInputs = with pkgs; [nix];
|
||||
};
|
||||
|
||||
theme = mkScript {
|
||||
name = "theme";
|
||||
file = ./theme.sh;
|
||||
runtimeInputs = with pkgs; [coreutils neovim tmux];
|
||||
replacements = {
|
||||
"@DEFAULT_MODE@" = theme.defaultMode;
|
||||
"@STATE_DIR@" = theme.paths.stateDir;
|
||||
"@STATE_FILE@" = theme.paths.stateFile;
|
||||
"@TMUX_DIR@" = theme.paths.tmuxDir;
|
||||
"@TMUX_CURRENT_FILE@" = theme.paths.tmuxCurrentFile;
|
||||
"@TMUX_DARK_FILE@" = "${tmuxConfigs.dark}";
|
||||
"@TMUX_LIGHT_FILE@" = "${tmuxConfigs.light}";
|
||||
"@TMUX_CONFIG@" = "${config.xdg.configHome}/tmux/tmux.conf";
|
||||
};
|
||||
};
|
||||
|
||||
wtc = mkScript {
|
||||
name = "wtc";
|
||||
file = ./wtc.sh;
|
||||
};
|
||||
};
|
||||
in {
|
||||
inherit packages theme tmuxConfigs;
|
||||
}
|
||||
9
scripts/ga.sh
Normal file
9
scripts/ga.sh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
if [[ $# -eq 0 ]]; then
|
||||
git add .
|
||||
else
|
||||
git add "$@"
|
||||
fi
|
||||
|
||||
if command -v critic >/dev/null 2>&1; then
|
||||
( critic review 2>/dev/null & )
|
||||
fi
|
||||
26
scripts/ghpr.sh
Normal file
26
scripts/ghpr.sh
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
base=$(git rev-parse --abbrev-ref HEAD)
|
||||
upstream="${1:-main}"
|
||||
remote_ref="origin/$upstream"
|
||||
unpushed=$(git log "$remote_ref"..HEAD --oneline 2>/dev/null)
|
||||
|
||||
if [[ -z "$unpushed" ]]; then
|
||||
if git diff --cached --quiet; then
|
||||
echo "No unpushed commits and no staged changes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "No unpushed commits, but staged changes found. Opening commit dialog..."
|
||||
git commit
|
||||
fi
|
||||
|
||||
msg=$(git log "$remote_ref"..HEAD --format='%s' --reverse | head -1)
|
||||
branch=$(echo "$msg" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
||||
|
||||
git checkout -b "$branch"
|
||||
git checkout "$base"
|
||||
git reset --hard "$remote_ref"
|
||||
git checkout "$branch"
|
||||
|
||||
git push -u origin "$branch"
|
||||
gh pr create --base "$upstream" --fill --web 2>/dev/null || gh pr create --base "$upstream" --fill
|
||||
gh pr view "$branch" --json url -q '.url'
|
||||
39
scripts/gpr.sh
Normal file
39
scripts/gpr.sh
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
while true; do
|
||||
pr=$(
|
||||
gh pr list --limit 50 \
|
||||
--json number,title,author,headRefName \
|
||||
--template '{{range .}}#{{.number}} {{.title}} ({{.author.login}}) [{{.headRefName}}]{{"\n"}}{{end}}' \
|
||||
| fzf --preview 'gh pr view {1} --comments' \
|
||||
--preview-window=right:60%:wrap \
|
||||
--header 'enter: view | ctrl-m: merge | ctrl-x: close | ctrl-o: checkout | ctrl-b: browser' \
|
||||
--bind 'ctrl-o:execute(gh pr checkout {1})' \
|
||||
--bind 'ctrl-b:execute(gh pr view {1} --web)' \
|
||||
--expect=ctrl-m,ctrl-x,enter
|
||||
)
|
||||
|
||||
[[ -z "$pr" ]] && exit 0
|
||||
|
||||
key=$(echo "$pr" | head -1)
|
||||
selection=$(echo "$pr" | tail -1)
|
||||
num=$(echo "$selection" | grep -o '#[0-9]*' | tr -d '#')
|
||||
|
||||
[[ -z "$num" ]] && exit 0
|
||||
|
||||
case "$key" in
|
||||
ctrl-m)
|
||||
read -r -p "Merge PR #$num? [y/N] " response
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
gh pr merge "$num" --merge
|
||||
fi
|
||||
;;
|
||||
ctrl-x)
|
||||
read -r -p "Close PR #$num? [y/N] " response
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
gh pr close "$num"
|
||||
fi
|
||||
;;
|
||||
enter|"")
|
||||
gh pr view "$num"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
51
scripts/iosrun.sh
Normal file
51
scripts/iosrun.sh
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
project=$(find . -maxdepth 1 -name "*.xcodeproj" | head -1)
|
||||
scheme=$(basename "$project" .xcodeproj)
|
||||
derived=".derived-data"
|
||||
sim_name="${1:-iPhone 16e}"
|
||||
|
||||
if [[ -z "$project" ]]; then
|
||||
echo "No .xcodeproj found in current directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building $scheme..."
|
||||
if ! xcodebuild -project "$project" -scheme "$scheme" \
|
||||
-destination "platform=iOS Simulator,name=$sim_name" \
|
||||
-derivedDataPath "$derived" build -quiet; then
|
||||
echo "Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Build succeeded. Launching simulator..."
|
||||
|
||||
xcrun simctl boot "$sim_name" 2>/dev/null || true
|
||||
open -a Simulator
|
||||
|
||||
app_path="$derived/Build/Products/Debug-iphonesimulator/$scheme.app"
|
||||
bundle_id=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$app_path/Info.plist")
|
||||
|
||||
echo "Installing $scheme..."
|
||||
while ! xcrun simctl install "$sim_name" "$app_path" 2>/dev/null; do
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
echo "Launching $bundle_id..."
|
||||
while ! xcrun simctl launch "$sim_name" "$bundle_id" 2>&1 | grep -q "$bundle_id"; do
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
echo "Launched $bundle_id - streaming logs (Ctrl+C to stop)"
|
||||
echo "----------------------------------------"
|
||||
|
||||
xcrun simctl spawn "$sim_name" log stream \
|
||||
--predicate "(subsystem CONTAINS '$bundle_id' OR process == '$scheme') AND NOT subsystem BEGINSWITH 'com.apple'" \
|
||||
--style compact \
|
||||
--color always 2>/dev/null | while read -r line; do
|
||||
if [[ "$line" == *"error"* ]] || [[ "$line" == *"Error"* ]]; then
|
||||
printf '\033[31m%s\033[0m\n' "$line"
|
||||
elif [[ "$line" == *"warning"* ]] || [[ "$line" == *"Warning"* ]]; then
|
||||
printf '\033[33m%s\033[0m\n' "$line"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done
|
||||
1
scripts/mdview.sh
Normal file
1
scripts/mdview.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
exec markserv "$@"
|
||||
6
scripts/ni.sh
Normal file
6
scripts/ni.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
if [[ $# -ne 1 ]]; then
|
||||
echo "usage: ni <package>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec nix profile add "nixpkgs#$1"
|
||||
71
scripts/theme.sh
Normal file
71
scripts/theme.sh
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
usage() {
|
||||
echo "usage: theme <dark|light|toggle|current>"
|
||||
}
|
||||
|
||||
read_mode() {
|
||||
if [[ -f "@STATE_FILE@" ]]; then
|
||||
mode=$(tr -d '[:space:]' < "@STATE_FILE@")
|
||||
if [[ "$mode" == "dark" || "$mode" == "light" ]]; then
|
||||
echo "$mode"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "@DEFAULT_MODE@"
|
||||
}
|
||||
|
||||
link_mode_assets() {
|
||||
local mode="$1"
|
||||
local tmux_target
|
||||
|
||||
case "$mode" in
|
||||
dark)
|
||||
tmux_target="@TMUX_DARK_FILE@"
|
||||
;;
|
||||
light)
|
||||
tmux_target="@TMUX_LIGHT_FILE@"
|
||||
;;
|
||||
*)
|
||||
echo "invalid mode: $mode" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "@STATE_DIR@" "@TMUX_DIR@"
|
||||
printf '%s\n' "$mode" > "@STATE_FILE@"
|
||||
ln -sfn "$tmux_target" "@TMUX_CURRENT_FILE@"
|
||||
|
||||
if command -v tmux >/dev/null 2>&1 && tmux start-server >/dev/null 2>&1; then
|
||||
tmux source-file "@TMUX_CONFIG@" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
for socket in /tmp/nvim-*.sock; do
|
||||
[[ -S "$socket" ]] || continue
|
||||
nvim --server "$socket" --remote-send "<Cmd>ThemeSync $mode<CR>" >/dev/null 2>&1 || true
|
||||
done
|
||||
}
|
||||
|
||||
mode="${1:-current}"
|
||||
|
||||
case "$mode" in
|
||||
dark|light)
|
||||
;;
|
||||
toggle)
|
||||
if [[ "$(read_mode)" == "dark" ]]; then
|
||||
mode="light"
|
||||
else
|
||||
mode="dark"
|
||||
fi
|
||||
;;
|
||||
current)
|
||||
read_mode
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
link_mode_assets "$mode"
|
||||
printf 'applied %s theme\n' "$mode"
|
||||
1
scripts/wtc.sh
Normal file
1
scripts/wtc.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
exec wt switch --create --base @ "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue