Autorefresh, BashExec and basename

- Auto `Refresh` every second.
- Add alias `BashExec` to message `Call` with args [`-c`, `bash` ...].

Also, Create alias `BashExec` to message `Call` with arguments [`bash`, `-c`]
pull/5/head
Arijit Basu 3 years ago committed by Arijit Basu
parent dba8631911
commit 67f2094a4c

@ -52,22 +52,22 @@ jobs:
with:
command: test
bench:
name: Benchmarks
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
# These dependencies are required for `clipboard`
- run: sudo apt-get install -y -qq libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- uses: actions-rs/cargo@v1
with:
command: bench
# bench:
# name: Benchmarks
# runs-on: ubuntu-latest
# needs: prepare
# steps:
# - uses: actions/checkout@master
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# profile: minimal
# override: true
# # These dependencies are required for `clipboard`
# - run: sudo apt-get install -y -qq libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
# - uses: actions-rs/cargo@v1
# with:
# command: bench
fmt:
name: Rustfmt

2
Cargo.lock generated

@ -1164,7 +1164,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xplr"
version = "0.2.19"
version = "0.2.20"
dependencies = [
"anyhow",
"chrono",

@ -1,6 +1,6 @@
[package]
name = "xplr"
version = "0.2.19" # Update app.rs
version = "0.2.20" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018"
description = "A hackable, minimal, fast TUI file explorer, stealing ideas from nnn and fzf"

@ -4,6 +4,16 @@
A hackable, minimal, fast TUI file explorer, stealing ideas from <a href="https://github.com/jarun/nnn">nnn</a> and <a href="https://github.com/junegunn/fzf">fzf</a>.
</p>
<p align="center">
<a href="https://github.com/sayanarijit/xplr/actions/workflows/ci.yml" target="_blank">
<img src="https://github.com/sayanarijit/xplr/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://github.com/sayanarijit/xplr/actions/workflows/cd.yml" target="_blank">
<img src="https://github.com/sayanarijit/xplr/actions/workflows/cd.yml/badge.svg" />
</a>
</p>
<p align="center">
<a href="https://asciinema.org/a/3THQPXNVi801Yu8nWxO6qfUa4" target="_blank">
<img src="https://s4.gifyu.com/images/xplr.gif" />
@ -21,11 +31,6 @@ A hackable, minimal, fast TUI file explorer, stealing ideas from <a href="https:
<br>
[![Continuous Integration](https://github.com/sayanarijit/xplr/actions/workflows/ci.yml/badge.svg)](https://github.com/sayanarijit/xplr/actions/workflows/ci.yml)
[![Continuous Delivery](https://github.com/sayanarijit/xplr/actions/workflows/cd.yml/badge.svg)](https://github.com/sayanarijit/xplr/actions/workflows/cd.yml)
<br>
Though [xplr](https://github.com/sayanarijit/xplr) strives to be fast and minimalist, it's speciality is it's hackability.
Once you read the [documentation](https://github.com/sayanarijit/xplr/wiki), you should be able to configure the key bindings,

@ -12,7 +12,7 @@ use std::fs;
use std::io;
use std::path::PathBuf;
pub const VERSION: &str = "v0.2.19"; // Update Cargo.toml
pub const VERSION: &str = "v0.2.20"; // Update Cargo.toml
pub const TEMPLATE_TABLE_ROW: &str = "TEMPLATE_TABLE_ROW";
@ -504,6 +504,12 @@ pub enum ExternalMsg {
/// Example: `Call: {command: bash, args: ["-c", "read -p test"]}`
Call(Command),
/// An alias to `Call: {command: bash, args: ["-c", "${command}"]}`
/// where ${command} is the given value.
///
/// Example: `BashExec: "read -p test"`
BashExec(String),
/// Select the focused node.
Select,
@ -816,6 +822,7 @@ impl App {
ExternalMsg::ResetInputBuffer => self.reset_input_buffer(),
ExternalMsg::SwitchMode(mode) => self.switch_mode(&mode),
ExternalMsg::Call(cmd) => self.call(cmd),
ExternalMsg::BashExec(cmd) => self.bash_exec(cmd),
ExternalMsg::Select => self.select(),
ExternalMsg::UnSelect => self.un_select(),
ExternalMsg::ToggleSelection => self.toggle_selection(),
@ -1065,6 +1072,13 @@ impl App {
Ok(self)
}
fn bash_exec(self, script: String) -> Result<Self> {
self.call(Command {
command: "bash".into(),
args: vec!["-c".into(), script],
})
}
fn add_directory(mut self, parent: String, dir: DirectoryBuffer) -> Result<Self> {
self.directory_buffers.insert(parent, dir);
self.msg_out.push_back(MsgOut::Refresh);

@ -0,0 +1,12 @@
use crate::app::{ExternalMsg, MsgIn, Task};
use std::sync::mpsc::Sender;
use std::thread;
use std::time::Duration;
pub fn start_auto_refreshing(tx: Sender<Task>) {
thread::spawn(move || loop {
tx.send(Task::new(3, MsgIn::External(ExternalMsg::Refresh), None))
.unwrap();
thread::sleep(Duration::from_secs(1));
});
}

@ -330,12 +330,8 @@ impl Default for KeyBindings {
help: rename
messages:
- SwitchMode: rename
- Call:
command: bash
args:
- -c
- |
echo "SetInputBuffer: ${XPLR_FOCUS_PATH}" >> "${XPLR_PIPE_MSG_IN:?}"
- BashExec: |
echo "SetInputBuffer: ${XPLR_FOCUS_PATH}" >> "${XPLR_PIPE_MSG_IN:?}"
".":
help: show hidden
@ -357,14 +353,10 @@ impl Default for KeyBindings {
"?":
help: global help menu
messages:
- Call:
command: bash
args:
- -c
- |
echo -e "${XPLR_GLOBAL_HELP_MENU}"
echo
read -p "[enter to continue]"
- BashExec: |
echo -e "${XPLR_GLOBAL_HELP_MENU}"
echo
read -p "[enter to continue]"
ctrl-c:
help: cancel & quit [q|esc]
@ -585,12 +577,8 @@ impl Default for Config {
x:
help: open in gui
messages:
- Call:
command: bash
args:
- -c
- |
xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
- BashExec: |
xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
- SwitchMode: default
ctrl-c:
@ -638,13 +626,9 @@ impl Default for Config {
l:
help: logs
messages:
- Call:
command: bash
args:
- -c
- |
echo -e "$XPLR_LOGS"
read -p "[enter to continue]"
- BashExec: |
echo -e "$XPLR_LOGS"
read -p "[enter to continue]"
- SwitchMode: default
ctrl-c:
@ -671,40 +655,32 @@ impl Default for Config {
c:
help: copy here
messages:
- Call:
command: bash
args:
- -c
- |
(while IFS= read -r line; do
if cp -v "${line:?}" ./; then
echo "LogSuccess: $line copied to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to copy $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- BashExec: |
(while IFS= read -r line; do
if cp -v "${line:?}" ./; then
echo "LogSuccess: $line copied to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to copy $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default
m:
help: move here
messages:
- Call:
command: bash
args:
- -c
- |
(while IFS= read -r line; do
if mv -v "${line:?}" ./; then
echo "LogSuccess: $line moved to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to move $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- BashExec: |
(while IFS= read -r line; do
if mv -v "${line:?}" ./; then
echo "LogSuccess: $line moved to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to move $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default
ctrl-c:
@ -816,19 +792,15 @@ impl Default for Config {
enter:
help: create file
messages:
- Call:
command: bash
args:
- -c
- |
PTH="${XPLR_INPUT_BUFFER:?}"
if touch "${PTH:?}"; then
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
echo Refresh >> "${XPLR_PIPE_MSG_IN:?}"
fi
- BashExec: |
PTH="${XPLR_INPUT_BUFFER:?}"
if touch "${PTH:?}"; then
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
echo Refresh >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default
backspace:
@ -861,18 +833,14 @@ impl Default for Config {
enter:
help: create directory
messages:
- Call:
command: bash
args:
- -c
- |
PTH="${XPLR_INPUT_BUFFER:?}"
if mkdir -p "$PTH"; then
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- BashExec: |
PTH="${XPLR_INPUT_BUFFER:?}"
if mkdir -p "$PTH"; then
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default
backspace:
@ -905,19 +873,15 @@ impl Default for Config {
enter:
help: rename
messages:
- Call:
command: bash
args:
- -c
- |
SRC="${XPLR_FOCUS_PATH:?}"
TARGET="${XPLR_INPUT_BUFFER:?}"
if mv -v "${SRC:?}" "${TARGET:?}"; then
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogSuccess: $SRC renamed to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to rename $SRC to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- BashExec: |
SRC="$(basename ${XPLR_FOCUS_PATH:?})"
TARGET="${XPLR_INPUT_BUFFER:?}"
if mv -v "${SRC:?}" "${TARGET:?}"; then
echo "LogSuccess: $SRC renamed to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to rename $SRC to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default
backspace:
@ -950,47 +914,39 @@ impl Default for Config {
d:
help: delete
messages:
- Call:
command: bash
args:
- -c
- |
(while IFS= read -r line; do
if [ -d "$line" ]; then
if rmdir -v "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
else
if rm -v "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- BashExec: |
(while IFS= read -r line; do
if [ -d "$line" ]; then
if rmdir -v "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
else
if rm -v "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default
D:
help: force delete
messages:
- Call:
command: bash
args:
- -c
- |
(while IFS= read -r line; do
if rm -rfv "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- BashExec: |
(while IFS= read -r line; do
if rm -rfv "${line:?}"; then
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default
- Explore

@ -3,6 +3,7 @@
#![allow(clippy::unnecessary_wraps)]
pub mod app;
pub mod auto_refresher;
pub mod config;
pub mod event_reader;
pub mod explorer;

@ -13,6 +13,7 @@ use termion::get_tty;
use tui::backend::CrosstermBackend;
use tui::Terminal;
use xplr::app;
use xplr::auto_refresher;
use xplr::event_reader;
use xplr::explorer;
use xplr::pipe_reader;
@ -72,6 +73,7 @@ fn main() -> Result<()> {
let mut terminal = Terminal::new(backend)?;
terminal.hide_cursor()?;
auto_refresher::start_auto_refreshing(tx_msg_in.clone());
pipe_reader::keep_reading(app.pipe().msg_in.clone(), tx_msg_in.clone());
event_reader::keep_reading(tx_msg_in.clone(), rx_event_reader);

Loading…
Cancel
Save