feat(fish): add Borderlands save write-protection toggle #217

Merged
alexion merged 1 commits from feat/bl2-readonly-toggle into main 2026-10-30 20:28:20 -04:00
2 changed files with 41 additions and 0 deletions
Showing only changes of commit 45f7e280d3 - Show all commits

No files matched your search

@@ -30,6 +30,7 @@ in
home-manager.users.${user} = { home-manager.users.${user} = {
home.packages = with pkgs; [ home.packages = with pkgs; [
bat # backs the manpager bat # backs the manpager
e2fsprogs # provides chattr and lsattr for the readonly function
fastfetch # the shell greeting fastfetch # the shell greeting
]; ];
@@ -99,6 +100,11 @@ in
body = builtins.readFile ./functions/deploy-to.fish; body = builtins.readFile ./functions/deploy-to.fish;
}; };
readonly = {
description = "Toggle write protection for a Borderlands 2 save";
body = builtins.readFile ./functions/readonly.fish;
};
}; };
# Rendered by home-manager into ~/.config/fish/config.fish. # Rendered by home-manager into ~/.config/fish/config.fish.
@@ -0,0 +1,35 @@
if test (count $argv) -ne 1
echo "usage: readonly <save-number>" >&2
return 2
end
set save_number $argv[1]
if not string match --quiet --regex '^[0-9]{4}$' -- "$save_number"
echo "readonly: save number must contain four digits" >&2
return 2
end
set save_name "Save$save_number.sav"
set save "$HOME/.local/share/Steam/steamapps/compatdata/49520/pfx/drive_c/users/steamuser/Documents/My games/Borderlands 2/WillowGame/SaveData/76561198060918970/$save_name"
if not test -f "$save"
echo "readonly: save not found: $save" >&2
return 1
end
set attribute_output (lsattr -d -- "$save")
or begin
echo "readonly: failed to read attributes for $save_name" >&2
return 1
end
set attribute_flags (string split --max 1 ' ' -- "$attribute_output")[1]
if string match --quiet '*i*' -- "$attribute_flags"
sudo chattr -i -- "$save"
or return $status
echo "$save_name is now writable"
else
sudo chattr +i -- "$save"
or return $status
echo "$save_name is now read-only"
end