feat(fish): add Borderlands save write-protection toggle #217
No files matched your search
@@ -30,6 +30,7 @@ in
|
||||
home-manager.users.${user} = {
|
||||
home.packages = with pkgs; [
|
||||
bat # backs the manpager
|
||||
e2fsprogs # provides chattr and lsattr for the readonly function
|
||||
fastfetch # the shell greeting
|
||||
];
|
||||
|
||||
@@ -99,6 +100,11 @@ in
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user