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

2
Cargo.lock generated

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

@ -1,6 +1,6 @@
[package] [package]
name = "xplr" name = "xplr"
version = "0.2.19" # Update app.rs version = "0.2.20" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"] authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018" edition = "2018"
description = "A hackable, minimal, fast TUI file explorer, stealing ideas from nnn and fzf" 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>. 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>
<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"> <p align="center">
<a href="https://asciinema.org/a/3THQPXNVi801Yu8nWxO6qfUa4" target="_blank"> <a href="https://asciinema.org/a/3THQPXNVi801Yu8nWxO6qfUa4" target="_blank">
<img src="https://s4.gifyu.com/images/xplr.gif" /> <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> <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. 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, 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::io;
use std::path::PathBuf; 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"; 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"]}` /// Example: `Call: {command: bash, args: ["-c", "read -p test"]}`
Call(Command), 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 the focused node.
Select, Select,
@ -816,6 +822,7 @@ impl App {
ExternalMsg::ResetInputBuffer => self.reset_input_buffer(), ExternalMsg::ResetInputBuffer => self.reset_input_buffer(),
ExternalMsg::SwitchMode(mode) => self.switch_mode(&mode), ExternalMsg::SwitchMode(mode) => self.switch_mode(&mode),
ExternalMsg::Call(cmd) => self.call(cmd), ExternalMsg::Call(cmd) => self.call(cmd),
ExternalMsg::BashExec(cmd) => self.bash_exec(cmd),
ExternalMsg::Select => self.select(), ExternalMsg::Select => self.select(),
ExternalMsg::UnSelect => self.un_select(), ExternalMsg::UnSelect => self.un_select(),
ExternalMsg::ToggleSelection => self.toggle_selection(), ExternalMsg::ToggleSelection => self.toggle_selection(),
@ -1065,6 +1072,13 @@ impl App {
Ok(self) 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> { fn add_directory(mut self, parent: String, dir: DirectoryBuffer) -> Result<Self> {
self.directory_buffers.insert(parent, dir); self.directory_buffers.insert(parent, dir);
self.msg_out.push_back(MsgOut::Refresh); 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 help: rename
messages: messages:
- SwitchMode: rename - SwitchMode: rename
- Call: - BashExec: |
command: bash echo "SetInputBuffer: ${XPLR_FOCUS_PATH}" >> "${XPLR_PIPE_MSG_IN:?}"
args:
- -c
- |
echo "SetInputBuffer: ${XPLR_FOCUS_PATH}" >> "${XPLR_PIPE_MSG_IN:?}"
".": ".":
help: show hidden help: show hidden
@ -357,14 +353,10 @@ impl Default for KeyBindings {
"?": "?":
help: global help menu help: global help menu
messages: messages:
- Call: - BashExec: |
command: bash echo -e "${XPLR_GLOBAL_HELP_MENU}"
args: echo
- -c read -p "[enter to continue]"
- |
echo -e "${XPLR_GLOBAL_HELP_MENU}"
echo
read -p "[enter to continue]"
ctrl-c: ctrl-c:
help: cancel & quit [q|esc] help: cancel & quit [q|esc]
@ -585,12 +577,8 @@ impl Default for Config {
x: x:
help: open in gui help: open in gui
messages: messages:
- Call: - BashExec: |
command: bash xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
args:
- -c
- |
xdg-open "${XPLR_FOCUS_PATH:?}" &> /dev/null
- SwitchMode: default - SwitchMode: default
ctrl-c: ctrl-c:
@ -638,13 +626,9 @@ impl Default for Config {
l: l:
help: logs help: logs
messages: messages:
- Call: - BashExec: |
command: bash echo -e "$XPLR_LOGS"
args: read -p "[enter to continue]"
- -c
- |
echo -e "$XPLR_LOGS"
read -p "[enter to continue]"
- SwitchMode: default - SwitchMode: default
ctrl-c: ctrl-c:
@ -671,40 +655,32 @@ impl Default for Config {
c: c:
help: copy here help: copy here
messages: messages:
- Call: - BashExec: |
command: bash (while IFS= read -r line; do
args: if cp -v "${line:?}" ./; then
- -c echo "LogSuccess: $line copied to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
- | else
(while IFS= read -r line; do echo "LogError: failed to copy $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
if cp -v "${line:?}" ./; then fi
echo "LogSuccess: $line copied to $PWD" >> "${XPLR_PIPE_MSG_IN:?}" done <<< "${XPLR_SELECTION:?}")
else echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogError: failed to copy $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}" echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}"
fi read -p "[enter to continue]"
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo ClearSelection >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default - SwitchMode: default
m: m:
help: move here help: move here
messages: messages:
- Call: - BashExec: |
command: bash (while IFS= read -r line; do
args: if mv -v "${line:?}" ./; then
- -c echo "LogSuccess: $line moved to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
- | else
(while IFS= read -r line; do echo "LogError: failed to move $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}"
if mv -v "${line:?}" ./; then fi
echo "LogSuccess: $line moved to $PWD" >> "${XPLR_PIPE_MSG_IN:?}" done <<< "${XPLR_SELECTION:?}")
else echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogError: failed to move $line to $PWD" >> "${XPLR_PIPE_MSG_IN:?}" read -p "[enter to continue]"
fi
done <<< "${XPLR_SELECTION:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default - SwitchMode: default
ctrl-c: ctrl-c:
@ -816,19 +792,15 @@ impl Default for Config {
enter: enter:
help: create file help: create file
messages: messages:
- Call: - BashExec: |
command: bash PTH="${XPLR_INPUT_BUFFER:?}"
args: if touch "${PTH:?}"; then
- -c echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
- | echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
PTH="${XPLR_INPUT_BUFFER:?}" else
if touch "${PTH:?}"; then echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}" echo Refresh >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}" fi
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
echo Refresh >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default - SwitchMode: default
backspace: backspace:
@ -861,18 +833,14 @@ impl Default for Config {
enter: enter:
help: create directory help: create directory
messages: messages:
- Call: - BashExec: |
command: bash PTH="${XPLR_INPUT_BUFFER:?}"
args: if mkdir -p "$PTH"; then
- -c echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
- | echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
PTH="${XPLR_INPUT_BUFFER:?}" else
if mkdir -p "$PTH"; then echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}" fi
echo "LogSuccess: $PTH created" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to create $PTH" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default - SwitchMode: default
backspace: backspace:
@ -905,19 +873,15 @@ impl Default for Config {
enter: enter:
help: rename help: rename
messages: messages:
- Call: - BashExec: |
command: bash SRC="$(basename ${XPLR_FOCUS_PATH:?})"
args: TARGET="${XPLR_INPUT_BUFFER:?}"
- -c if mv -v "${SRC:?}" "${TARGET:?}"; then
- | echo "LogSuccess: $SRC renamed to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
SRC="${XPLR_FOCUS_PATH:?}" echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
TARGET="${XPLR_INPUT_BUFFER:?}" else
if mv -v "${SRC:?}" "${TARGET:?}"; then echo "LogError: failed to rename $SRC to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
echo Explore >> "${XPLR_PIPE_MSG_IN:?}" fi
echo "LogSuccess: $SRC renamed to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: failed to rename $SRC to $TARGET" >> "${XPLR_PIPE_MSG_IN:?}"
fi
- SwitchMode: default - SwitchMode: default
backspace: backspace:
@ -950,47 +914,39 @@ impl Default for Config {
d: d:
help: delete help: delete
messages: messages:
- Call: - BashExec: |
command: bash (while IFS= read -r line; do
args: if [ -d "$line" ]; then
- -c if rmdir -v "${line:?}"; then
- | echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
(while IFS= read -r line; do else
if [ -d "$line" ]; then echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
if rmdir -v "${line:?}"; then fi
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}" else
else if rm -v "${line:?}"; then
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}" echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
fi else
else echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
if rm -v "${line:?}"; then fi
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}" fi
else done <<< "${XPLR_RESULT:?}")
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}" echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
fi read -p "[enter to continue]"
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default - SwitchMode: default
D: D:
help: force delete help: force delete
messages: messages:
- Call: - BashExec: |
command: bash (while IFS= read -r line; do
args: if rm -rfv "${line:?}"; then
- -c echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}"
- | else
(while IFS= read -r line; do echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}"
if rm -rfv "${line:?}"; then fi
echo "LogSuccess: $line deleted" >> "${XPLR_PIPE_MSG_IN:?}" done <<< "${XPLR_RESULT:?}")
else echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
echo "LogError: failed to delete $line" >> "${XPLR_PIPE_MSG_IN:?}" read -p "[enter to continue]"
fi
done <<< "${XPLR_RESULT:?}")
echo Explore >> "${XPLR_PIPE_MSG_IN:?}"
read -p "[enter to continue]"
- SwitchMode: default - SwitchMode: default
- Explore - Explore

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

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

Loading…
Cancel
Save