summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2026-03-15 00:14:14 +0100
committerDaniel Weipert <git@mail.dweipert.de>2026-03-15 00:14:14 +0100
commitff750baf52a91582d53eaccb76e09318a51cafa7 (patch)
treeccceab302fcb25ade2c2e5463822a68c7214d075
parent9c0e46b834a64f2a329518de19c8d7319e3c77b3 (diff)
add command to set remote as default
-rwxr-xr-xrclone-ide35
1 files changed, 32 insertions, 3 deletions
diff --git a/rclone-ide b/rclone-ide
index 7d6c5c0..46ba72d 100755
--- a/rclone-ide
+++ b/rclone-ide
@@ -33,7 +33,7 @@ def find_config_file() -> str:
current_dir = os.getcwd()
while config_file == "":
for entry in os.scandir(current_dir):
- if "rclone.conf" in entry.path:
+ if entry.path.endswith("rclone.conf") and os.path.isfile(entry.path):
config_file = entry.path
config_dir = current_dir
@@ -62,7 +62,7 @@ def get_config() -> Mapping[str, Mapping[str, Any]]:
config = get_config()
-def get_remote_config(remote: str = "") -> Optional[Mapping[str, Mapping[str, Any]]]:
+def get_remote_config(remote: str = "") -> Mapping[str, Mapping[str, Any]]:
"""Get config for specific remote. Fall back to default if unspecified"""
global config
@@ -89,7 +89,7 @@ def get_remote_config(remote: str = "") -> Optional[Mapping[str, Mapping[str, An
"config": remote_config,
}
- return None
+ raise KeyError("No remote set as default")
def build_cmd_local_path(config: Mapping[str, Any]) -> str:
@@ -179,6 +179,30 @@ def command_set_remote_path(options: Mapping[str, Any]) -> None:
subprocess.run(cmd)
+def command_set_default_remote(options: Mapping[str, Any]) -> None:
+ """Set the config option for the given remote to mark it as default"""
+
+ cmd = [
+ "rclone", "config", "update",
+ options.remote,
+ "rclone_ide_default", "true",
+ build_cmd_config(),
+ ]
+
+ if options.dry_run:
+ print(" ".join(cmd))
+ else:
+ with open(config_file, "r+") as file:
+ lines = file.readlines()
+ file.seek(0)
+ for line in lines:
+ if "rclone_ide_default =" not in line:
+ file.write(line)
+ file.truncate()
+
+ subprocess.run(cmd)
+
+
def command_copy_file(options: Mapping[str, Any]) -> None:
"""Copy specific file to remote"""
@@ -228,6 +252,9 @@ parser_set_remote_path = subparsers.add_parser("set-remote-path")
parser_set_remote_path.add_argument("remote", choices=config.keys())
parser_set_remote_path.add_argument("remote_path")
+parser_set_default_remote = subparsers.add_parser("set-default-remote")
+parser_set_default_remote.add_argument("remote", choices=config.keys())
+
parser_copy_file = subparsers.add_parser("copy-file")
parser_copy_file.add_argument("remote", help="rclone remote to upload to. @ = default remote", choices=[*config.keys(), "@"])
@@ -243,6 +270,8 @@ if args.command:
command_set_local_path(args)
case "set-remote-path":
command_set_remote_path(args)
+ case "set-default-remote":
+ command_set_default_remote(args)
case "copy-file":
command_copy_file(args)