diff --git a/docs/en/src/default-key-bindings.md b/docs/en/src/default-key-bindings.md index fc8ce32..13ec654 100644 --- a/docs/en/src/default-key-bindings.md +++ b/docs/en/src/default-key-bindings.md @@ -18,6 +18,7 @@ of [modes][4] and the key mappings for each mode. | G | | go to bottom | | V | ctrl-a | select/unselect all | | ctrl-c | | terminate | +| ctrl-d | | duplicate as | | ctrl-i | tab | next visited path | | ctrl-o | | last visited path | | ctrl-r | | refresh screen | @@ -38,10 +39,10 @@ of [modes][4] and the key mappings for each mode. | ~ | | go home | | [0-9] | | input | -### debug +### debug error | key | remaps | action | -| -------| ------ | --------------------| +| ------ | ------ | ------------------- | | ctrl-c | | terminate | | enter | | open logs in editor | | esc | | escape | @@ -156,6 +157,14 @@ of [modes][4] and the key mappings for each mode. | enter | | rename | | esc | | cancel | +### duplicate as + +| key | remaps | action | +| ------ | ------ | --------- | +| ctrl-c | | terminate | +| enter | | duplicate | +| esc | | cancel | + ### delete | key | remaps | action | diff --git a/src/app.rs b/src/app.rs index b5431b3..4eb8c6c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2689,6 +2689,7 @@ impl App { &builtin.create_file, &builtin.create_directory, &builtin.rename, + &builtin.duplicate_as, &builtin.delete, &builtin.sort, &builtin.filter, diff --git a/src/config.rs b/src/config.rs index 8cc69ac..8402ead 100644 --- a/src/config.rs +++ b/src/config.rs @@ -550,6 +550,9 @@ pub struct BuiltinModesConfig { #[serde(default)] pub rename: Mode, + #[serde(default)] + pub duplicate_as: Mode, + #[serde(default)] pub delete: Mode, @@ -595,6 +598,8 @@ impl BuiltinModesConfig { "go to" => Some(&self.go_to), "go_to" => Some(&self.go_to), "rename" => Some(&self.rename), + "duplicate as" => Some(&self.duplicate_as), + "duplicate_as" => Some(&self.duplicate_as), "delete" => Some(&self.delete), "action" => Some(&self.action), "search" => Some(&self.search), diff --git a/src/init.lua b/src/init.lua index 1bd8526..48de143 100644 --- a/src/init.lua +++ b/src/init.lua @@ -904,6 +904,18 @@ xplr.config.modes.builtin.default = { }, }, }, + ["ctrl-d"] = { + help = "duplicate as", + messages = { + "PopMode", + { SwitchModeBuiltin = "duplicate_as" }, + { + BashExecSilently = [===[ + echo SetInputBuffer: "'"$(basename "${XPLR_FOCUS_PATH}")"'" >> "${XPLR_PIPE_MSG_IN:?}" + ]===], + }, + }, + }, right = { help = "enter", messages = { @@ -1454,10 +1466,63 @@ xplr.config.modes.builtin.rename = { BashExecSilently = [===[ SRC="${XPLR_FOCUS_PATH:?}" TARGET="${XPLR_INPUT_BUFFER:?}" - mv -- "${SRC:?}" "${TARGET:?}" \ - && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ - && echo FocusByFileName: "'"$TARGET"'" >> "${XPLR_PIPE_MSG_IN:?}" \ - && echo LogSuccess: $SRC renamed to $TARGET >> "${XPLR_PIPE_MSG_IN:?}" + if [ -e "${TARGET:?}" ]; then + echo LogError: $TARGET already exists >> "${XPLR_PIPE_MSG_IN:?}" + else + mv -- "${SRC:?}" "${TARGET:?}" \ + && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ + && echo FocusPath: "'"$TARGET"'" >> "${XPLR_PIPE_MSG_IN:?}" \ + && echo LogSuccess: $SRC renamed to $TARGET >> "${XPLR_PIPE_MSG_IN:?}" + fi + ]===], + }, + "PopMode", + }, + }, + esc = { + help = "cancel", + messages = { + "PopMode", + }, + }, + }, + default = { + help = nil, + messages = { + "UpdateInputBufferFromKey", + }, + }, + }, +} + +------ Duplicate as +xplr.config.modes.builtin.duplicate_as = { + name = "duplicate as", + help = nil, + extra_help = nil, + key_bindings = { + on_key = { + ["ctrl-c"] = { + help = "terminate", + messages = { + "Terminate", + }, + }, + enter = { + help = "duplicate", + messages = { + { + BashExecSilently = [===[ + SRC="${XPLR_FOCUS_PATH:?}" + TARGET="${XPLR_INPUT_BUFFER:?}" + if [ -e "${TARGET:?}" ]; then + echo LogError: $TARGET already exists >> "${XPLR_PIPE_MSG_IN:?}" + else + cp -r -- "${SRC:?}" "${TARGET:?}" \ + && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ + && echo FocusPath: "'"$TARGET"'" >> "${XPLR_PIPE_MSG_IN:?}" \ + && echo LogSuccess: $SRC duplicated as $TARGET >> "${XPLR_PIPE_MSG_IN:?}" + fi ]===], }, "PopMode",