Minor improvements

This commit is contained in:
Arijit Basu 2022-10-24 10:03:16 +05:30
parent 89b3731b56
commit c93202b649
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077
3 changed files with 74 additions and 138 deletions

View File

@ -58,6 +58,9 @@ fn main() {
match runner::from_cli(cli).and_then(|a| a.run()) { match runner::from_cli(cli).and_then(|a| a.run()) {
Ok(Some(mut out)) => { Ok(Some(mut out)) => {
if write0 { if write0 {
if out.ends_with('\n') {
out = out.chars().take(out.chars().count() - 1).collect()
};
out = out out = out
.trim_end() .trim_end()
.chars() .chars()

View File

@ -1029,10 +1029,7 @@ xplr.config.modes.builtin.default = {
help = "show hidden", help = "show hidden",
messages = { messages = {
{ {
ToggleNodeFilter = { ToggleNodeFilter = { filter = "RelativePathDoesNotStartWith", input = "." },
filter = "RelativePathDoesNotStartWith",
input = ".",
},
}, },
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
@ -1159,7 +1156,7 @@ xplr.config.modes.builtin.default = {
{ {
BashExecSilently = [===[ BashExecSilently = [===[
NAME=$(basename "${XPLR_FOCUS_PATH:?}") NAME=$(basename "${XPLR_FOCUS_PATH:?}")
echo SetInputBuffer: "'"${NAME:?}"'" >> "${XPLR_PIPE_MSG_IN:?}" echo SetInputBuffer: "'${NAME:?}'" >> "${XPLR_PIPE_MSG_IN:?}"
]===], ]===],
}, },
}, },
@ -1172,7 +1169,7 @@ xplr.config.modes.builtin.default = {
{ {
BashExecSilently = [===[ BashExecSilently = [===[
NAME=$(basename "${XPLR_FOCUS_PATH:?}") NAME=$(basename "${XPLR_FOCUS_PATH:?}")
echo SetInputBuffer: "'"${NAME:?}"'" >> "${XPLR_PIPE_MSG_IN:?}" echo SetInputBuffer: "'${NAME:?}'" >> "${XPLR_PIPE_MSG_IN:?}"
]===], ]===],
}, },
}, },
@ -1208,7 +1205,7 @@ xplr.config.modes.builtin.default = {
messages = { messages = {
{ {
BashExecSilently = [===[ BashExecSilently = [===[
echo ChangeDirectory: "'"${HOME:?}"'" >> "${XPLR_PIPE_MSG_IN:?}" echo ChangeDirectory: "'${HOME:?}'" >> "${XPLR_PIPE_MSG_IN:?}"
]===], ]===],
}, },
}, },
@ -1249,29 +1246,14 @@ xplr.config.modes.builtin.default = {
}, },
} }
xplr.config.modes.builtin.default.key_bindings.on_key["tab"] = xplr.config.modes.builtin.default.key_bindings.on_key["tab"] = xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"]
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"] xplr.config.modes.builtin.default.key_bindings.on_key["v"] = xplr.config.modes.builtin.default.key_bindings.on_key["space"]
xplr.config.modes.builtin.default.key_bindings.on_key["V"] = xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"]
xplr.config.modes.builtin.default.key_bindings.on_key["v"] = xplr.config.modes.builtin.default.key_bindings.on_key["/"] = xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"]
xplr.config.modes.builtin.default.key_bindings.on_key.space xplr.config.modes.builtin.default.key_bindings.on_key["h"] = xplr.config.modes.builtin.default.key_bindings.on_key["left"]
xplr.config.modes.builtin.default.key_bindings.on_key["j"] = xplr.config.modes.builtin.default.key_bindings.on_key["down"]
xplr.config.modes.builtin.default.key_bindings.on_key["V"] = xplr.config.modes.builtin.default.key_bindings.on_key["k"] = xplr.config.modes.builtin.default.key_bindings.on_key["up"]
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"] xplr.config.modes.builtin.default.key_bindings.on_key["l"] = xplr.config.modes.builtin.default.key_bindings.on_key["right"]
xplr.config.modes.builtin.default.key_bindings.on_key["/"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"]
xplr.config.modes.builtin.default.key_bindings.on_key["h"] =
xplr.config.modes.builtin.default.key_bindings.on_key.left
xplr.config.modes.builtin.default.key_bindings.on_key["j"] =
xplr.config.modes.builtin.default.key_bindings.on_key.down
xplr.config.modes.builtin.default.key_bindings.on_key["k"] =
xplr.config.modes.builtin.default.key_bindings.on_key.up
xplr.config.modes.builtin.default.key_bindings.on_key["l"] =
xplr.config.modes.builtin.default.key_bindings.on_key.right
-- The builtin debug error mode. -- The builtin debug error mode.
-- --
@ -1320,7 +1302,7 @@ xplr.config.modes.builtin.debug_error = {
messages = { messages = {
{ {
BashExec = [===[ BashExec = [===[
${EDITOR:-vi} "${XPLR_PIPE_LOGS_OUT:?}" cat "${XPLR_PIPE_LOGS_OUT:?}" | ${EDITOR:-vi} -
]===], ]===],
}, },
}, },
@ -1382,9 +1364,9 @@ xplr.config.modes.builtin.go_to_path = {
{ {
BashExecSilently = [===[ BashExecSilently = [===[
if [ -d "$XPLR_INPUT_BUFFER" ]; then if [ -d "$XPLR_INPUT_BUFFER" ]; then
echo ChangeDirectory: "'"$XPLR_INPUT_BUFFER"'" >> "${XPLR_PIPE_MSG_IN:?}" echo ChangeDirectory: "'$XPLR_INPUT_BUFFER'" >> "${XPLR_PIPE_MSG_IN:?}"
elif [ -e "$XPLR_INPUT_BUFFER" ]; then elif [ -e "$XPLR_INPUT_BUFFER" ]; then
echo FocusPath: "'"$XPLR_INPUT_BUFFER"'" >> "${XPLR_PIPE_MSG_IN:?}" echo FocusPath: "'$XPLR_INPUT_BUFFER'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
]===], ]===],
}, },
@ -1419,11 +1401,11 @@ xplr.config.modes.builtin.selection_ops = {
{ {
BashExec = [===[ BashExec = [===[
(while IFS= read -r line; do (while IFS= read -r line; do
if cp -vr -- "${line:?}" ./; then if cp -vr -- "${line:?}" ./; then
echo LogSuccess: $line copied to $PWD >> "${XPLR_PIPE_MSG_IN:?}" echo LogSuccess: "'$line copied to $PWD'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo LogError: Failed to copy $line to $PWD >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'Failed to copy $line to $PWD'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
done < "${XPLR_PIPE_SELECTION_OUT:?}") done < "${XPLR_PIPE_SELECTION_OUT:?}")
echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}" echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}" echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}"
@ -1439,11 +1421,11 @@ xplr.config.modes.builtin.selection_ops = {
{ {
BashExec = [===[ BashExec = [===[
(while IFS= read -r line; do (while IFS= read -r line; do
if mv -v -- "${line:?}" ./; then if mv -v -- "${line:?}" ./; then
echo LogSuccess: $line moved to $PWD >> "${XPLR_PIPE_MSG_IN:?}" echo LogSuccess: "'$line moved to $PWD'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo LogError: Failed to move $line to $PWD >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'Failed to move $line to $PWD'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
done < "${XPLR_PIPE_SELECTION_OUT:?}") done < "${XPLR_PIPE_SELECTION_OUT:?}")
echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}" echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]" read -p "[enter to continue]"
@ -1470,12 +1452,12 @@ xplr.config.modes.builtin.selection_ops = {
elif command -v open; then elif command -v open; then
OPENER=open OPENER=open
else else
echo 'LogError: $OPENER not found' >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: '$OPENER not found' >> "${XPLR_PIPE_MSG_IN:?}"
exit 1 exit 1
fi fi
fi fi
(while IFS= read -r line; do (while IFS= read -r line; do
$OPENER "${line:?}" > /dev/null 2>&1 $OPENER "${line:?}" > /dev/null 2>&1
done < "${XPLR_PIPE_RESULT_OUT:?}") done < "${XPLR_PIPE_RESULT_OUT:?}")
]===], ]===],
}, },
@ -1536,10 +1518,10 @@ xplr.config.modes.builtin.create_directory = {
PTH="$XPLR_INPUT_BUFFER" PTH="$XPLR_INPUT_BUFFER"
if [ "${PTH}" ]; then if [ "${PTH}" ]; then
mkdir -p -- "${PTH:?}" \ mkdir -p -- "${PTH:?}" \
&& echo "SetInputBuffer: ''" >> "${XPLR_PIPE_MSG_IN:?}" \ && echo SetInputBuffer: "''" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo LogSuccess: $PTH created >> "${XPLR_PIPE_MSG_IN:?}" \ && echo LogSuccess: "'$PTH created'" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo FocusPath: "'"$PTH"'" >> "${XPLR_PIPE_MSG_IN:?}" && echo FocusPath: "'$PTH'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo PopMode >> "${XPLR_PIPE_MSG_IN:?}" echo PopMode >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
@ -1579,10 +1561,10 @@ xplr.config.modes.builtin.create_file = {
if [ "$PTH" ]; then if [ "$PTH" ]; then
mkdir -p -- "$(dirname $PTH)" \ mkdir -p -- "$(dirname $PTH)" \
&& touch -- "$PTH" \ && touch -- "$PTH" \
&& echo "SetInputBuffer: ''" >> "${XPLR_PIPE_MSG_IN:?}" \ && echo SetInputBuffer: "''" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo LogSuccess: $PTH created >> "${XPLR_PIPE_MSG_IN:?}" \ && echo LogSuccess: "'$PTH created'" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo FocusPath: "'"$PTH"'" >> "${XPLR_PIPE_MSG_IN:?}" && echo FocusPath: "'$PTH'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo PopMode >> "${XPLR_PIPE_MSG_IN:?}" echo PopMode >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
@ -1643,10 +1625,8 @@ xplr.config.modes.builtin.number = {
}, },
} }
xplr.config.modes.builtin.number.key_bindings.on_key["j"] = xplr.config.modes.builtin.number.key_bindings.on_key["j"] = xplr.config.modes.builtin.number.key_bindings.on_key["down"]
xplr.config.modes.builtin.number.key_bindings.on_key.down xplr.config.modes.builtin.number.key_bindings.on_key["k"] = xplr.config.modes.builtin.number.key_bindings.on_key["up"]
xplr.config.modes.builtin.number.key_bindings.on_key["k"] =
xplr.config.modes.builtin.number.key_bindings.on_key.up
-- The builtin go to mode. -- The builtin go to mode.
-- --
@ -1688,7 +1668,7 @@ xplr.config.modes.builtin.go_to = {
elif command -v open; then elif command -v open; then
OPENER=open OPENER=open
else else
echo 'LogError: $OPENER not found' >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: '$OPENER not found' >> "${XPLR_PIPE_MSG_IN:?}"
exit 1 exit 1
fi fi
fi fi
@ -1724,12 +1704,12 @@ xplr.config.modes.builtin.rename = {
SRC="${XPLR_FOCUS_PATH:?}" SRC="${XPLR_FOCUS_PATH:?}"
TARGET="${XPLR_INPUT_BUFFER:?}" TARGET="${XPLR_INPUT_BUFFER:?}"
if [ -e "${TARGET:?}" ]; then if [ -e "${TARGET:?}" ]; then
echo LogError: $TARGET already exists >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'$TARGET already exists'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
mv -- "${SRC:?}" "${TARGET:?}" \ mv -- "${SRC:?}" "${TARGET:?}" \
&& echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo FocusPath: "'"$TARGET"'" >> "${XPLR_PIPE_MSG_IN:?}" \ && echo FocusPath: "'$TARGET'" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo LogSuccess: $SRC renamed to $TARGET >> "${XPLR_PIPE_MSG_IN:?}" && echo LogSuccess: "'$SRC renamed to $TARGET'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
]===], ]===],
}, },
@ -1766,12 +1746,12 @@ xplr.config.modes.builtin.duplicate_as = {
SRC="${XPLR_FOCUS_PATH:?}" SRC="${XPLR_FOCUS_PATH:?}"
TARGET="${XPLR_INPUT_BUFFER:?}" TARGET="${XPLR_INPUT_BUFFER:?}"
if [ -e "${TARGET:?}" ]; then if [ -e "${TARGET:?}" ]; then
echo LogError: $TARGET already exists >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'$TARGET already exists'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
cp -r -- "${SRC:?}" "${TARGET:?}" \ cp -r -- "${SRC:?}" "${TARGET:?}" \
&& echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \ && echo ExplorePwd >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo FocusPath: "'"$TARGET"'" >> "${XPLR_PIPE_MSG_IN:?}" \ && echo FocusPath: "'$TARGET'" >> "${XPLR_PIPE_MSG_IN:?}" \
&& echo LogSuccess: $SRC duplicated as $TARGET >> "${XPLR_PIPE_MSG_IN:?}" && echo LogSuccess: "'$SRC duplicated as $TARGET'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
]===], ]===],
}, },
@ -1800,11 +1780,11 @@ xplr.config.modes.builtin.delete = {
{ {
BashExec = [===[ BashExec = [===[
(while IFS= read -r line; do (while IFS= read -r line; do
if rm -rfv -- "${line:?}"; then if rm -rfv -- "${line:?}"; then
echo LogSuccess: $line deleted >> "${XPLR_PIPE_MSG_IN:?}" echo LogSuccess: "'$line deleted'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo LogError: Failed to delete $line >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'Failed to delete $line'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
done < "${XPLR_PIPE_RESULT_OUT:?}") done < "${XPLR_PIPE_RESULT_OUT:?}")
echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}" echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]" read -p "[enter to continue]"
@ -1821,15 +1801,15 @@ xplr.config.modes.builtin.delete = {
(while IFS= read -r line; do (while IFS= read -r line; do
if [ -d "$line" ] && [ ! -L "$line" ]; then if [ -d "$line" ] && [ ! -L "$line" ]; then
if rmdir -v -- "${line:?}"; then if rmdir -v -- "${line:?}"; then
echo LogSuccess: $line deleted >> "${XPLR_PIPE_MSG_IN:?}" echo LogSuccess: "'$line deleted'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo LogError: Failed to delete $line >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'Failed to delete $line'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
else else
if rm -v -- "${line:?}"; then if rm -v -- "${line:?}"; then
echo LogSuccess: $line deleted >> "${XPLR_PIPE_MSG_IN:?}" echo LogSuccess: "'$line deleted'" >> "${XPLR_PIPE_MSG_IN:?}"
else else
echo LogError: Failed to delete $line >> "${XPLR_PIPE_MSG_IN:?}" echo LogError: "'Failed to delete $line'" >> "${XPLR_PIPE_MSG_IN:?}"
fi fi
fi fi
done < "${XPLR_PIPE_RESULT_OUT:?}") done < "${XPLR_PIPE_RESULT_OUT:?}")
@ -2029,10 +2009,8 @@ xplr.config.modes.builtin.search = {
}, },
} }
xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-n"] = xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-n"] = xplr.config.modes.builtin.search.key_bindings.on_key["down"]
xplr.config.modes.builtin.search.key_bindings.on_key.down xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-p"] = xplr.config.modes.builtin.search.key_bindings.on_key["up"]
xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-p"] =
xplr.config.modes.builtin.search.key_bindings.on_key.up
-- The builtin filter mode. -- The builtin filter mode.
-- --
@ -2167,72 +2145,37 @@ xplr.config.modes.builtin.sort = {
["E"] = { ["E"] = {
help = "by canonical extension reverse", help = "by canonical extension reverse",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalExtension", reverse = true } },
AddNodeSorter = {
sorter = "ByCanonicalExtension",
reverse = true,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
["M"] = { ["M"] = {
help = "by canonical mime essence reverse", help = "by canonical mime essence reverse",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalMimeEssence", reverse = true } },
AddNodeSorter = {
sorter = "ByCanonicalMimeEssence",
reverse = true,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
["N"] = { ["N"] = {
help = "by node type reverse", help = "by node type reverse",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalIsDir", reverse = true } },
AddNodeSorter = { { AddNodeSorter = { sorter = "ByCanonicalIsFile", reverse = true } },
sorter = "ByCanonicalIsDir", { AddNodeSorter = { sorter = "ByIsSymlink", reverse = true } },
reverse = true,
},
},
{
AddNodeSorter = {
sorter = "ByCanonicalIsFile",
reverse = true,
},
},
{
AddNodeSorter = {
sorter = "ByIsSymlink",
reverse = true,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
["R"] = { ["R"] = {
help = "by relative path reverse", help = "by relative path reverse",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByIRelativePath", reverse = true } },
AddNodeSorter = {
sorter = "ByIRelativePath",
reverse = true,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
["S"] = { ["S"] = {
help = "by size reverse", help = "by size reverse",
messages = { messages = {
{ { AddNodeSorter = { sorter = "BySize", reverse = true } },
AddNodeSorter = {
sorter = "BySize",
reverse = true,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
@ -2260,12 +2203,7 @@ xplr.config.modes.builtin.sort = {
["e"] = { ["e"] = {
help = "by canonical extension", help = "by canonical extension",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalExtension", reverse = false } },
AddNodeSorter = {
sorter = "ByCanonicalExtension",
reverse = false,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
@ -2278,27 +2216,16 @@ xplr.config.modes.builtin.sort = {
["m"] = { ["m"] = {
help = "by canonical mime essence", help = "by canonical mime essence",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalMimeEssence", reverse = false } },
AddNodeSorter = {
sorter = "ByCanonicalMimeEssence",
reverse = false,
},
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },
["n"] = { ["n"] = {
help = "by node type", help = "by node type",
messages = { messages = {
{ { AddNodeSorter = { sorter = "ByCanonicalIsDir", reverse = false } },
AddNodeSorter = { sorter = "ByCanonicalIsDir", reverse = false }, { AddNodeSorter = { sorter = "ByCanonicalIsFile", reverse = false } },
}, { AddNodeSorter = { sorter = "ByIsSymlink", reverse = false } },
{
AddNodeSorter = { sorter = "ByCanonicalIsFile", reverse = false },
},
{
AddNodeSorter = { sorter = "ByIsSymlink", reverse = false },
},
"ExplorePwdAsync", "ExplorePwdAsync",
}, },
}, },

View File

@ -255,6 +255,12 @@ impl Runner {
tx_msg_in.send(app::Task::new(app::MsgIn::External(msg), None))?; tx_msg_in.send(app::Task::new(app::MsgIn::External(msg), None))?;
} }
// Refresh once after loading
tx_msg_in.send(app::Task::new(
app::MsgIn::External(app::ExternalMsg::Refresh),
None,
))?;
'outer: for task in rx_msg_in { 'outer: for task in rx_msg_in {
match app.handle_task(task) { match app.handle_task(task) {
Ok(a) => { Ok(a) => {