summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-05-28 00:50:15 +0200
committerrabite <rabite@posteo.de>2019-05-28 00:51:47 +0200
commitad4e3d573fffe2412c7840319c39ca4a64c02b56 (patch)
tree06a8e64a71859fbb448cc37e523b8bcc8ab606d2
parentfdc4eb52d0403e041fe77f403b0dbc5686789087 (diff)
add quick actions
-rw-r--r--Cargo.lock77
-rw-r--r--Cargo.toml1
-rw-r--r--README.md21
-rwxr-xr-xextra/actions/application/extract.sh10
-rwxr-xr-xextra/actions/compress?archive_name.sh3
-rwxr-xr-xextra/actions/synchtop!.sh3
-rwxr-xr-xextra/actions/text/firefox.sh3
-rwxr-xr-xextra/actions/text/nano!.sh3
-rwxr-xr-xextra/actions/video/mpv.sh3
-rwxr-xr-xextra/actions/youtube_music?url.sh15
-rw-r--r--src/file_browser.rs19
-rw-r--r--src/foldview.rs43
-rw-r--r--src/hbox.rs2
-rw-r--r--src/listview.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/paths.rs6
-rw-r--r--src/preview.rs2
-rw-r--r--src/proclist.rs4
-rw-r--r--src/textview.rs2
19 files changed, 162 insertions, 59 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3b60dfe..bc61487 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -45,7 +45,7 @@ dependencies = [
[[package]]
name = "async_value"
-version = "0.2.3"
+version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -66,15 +66,15 @@ dependencies = [
[[package]]
name = "autocfg"
-version = "0.1.2"
+version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "backtrace"
-version = "0.3.20"
+version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -129,8 +129,8 @@ name = "chrono"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "num-integer 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -236,7 +236,7 @@ name = "failure"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "backtrace 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -439,7 +439,7 @@ name = "hunter"
version = "1.2.1"
dependencies = [
"alphanumeric-sort 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "async_value 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "async_value 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs-2 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -451,6 +451,7 @@ dependencies = [
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
"lscolors 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 4.0.12 (registry+https://github.com/rust-lang/crates.io-index)",
"osstrtools 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -474,9 +475,9 @@ dependencies = [
"gif 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-iter 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -615,7 +616,7 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.6.17"
+version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -637,7 +638,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "mio 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mio 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -697,7 +698,7 @@ dependencies = [
"inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
- "mio 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mio 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -715,21 +716,21 @@ dependencies = [
[[package]]
name = "num-integer"
-version = "0.1.40"
+version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
-version = "0.1.38"
+version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-integer 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -737,8 +738,8 @@ name = "num-rational"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "num-integer 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -746,16 +747,16 @@ name = "num-rational"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "num-integer 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
-version = "0.2.7"
+version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -883,7 +884,7 @@ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)",
"inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-iter 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -919,7 +920,7 @@ name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -937,7 +938,7 @@ name = "rand_chacha"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -998,7 +999,7 @@ name = "rand_pcg"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1221,7 +1222,7 @@ dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1363,10 +1364,10 @@ dependencies = [
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
-"checksum async_value 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e9c7275a202ffc12d7307fc4899390c3c64af7198c49015b3242c11892f93414"
+"checksum async_value 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e59ea0ca05a6f84b5ce4689a5b9610cccf587190688daaaea1835b08b7c7ccc0"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
-"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
-"checksum backtrace 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "45934a579eff9fd0ff637ac376a4bd134f47f8fc603f0b211d696b54d61e35f1"
+"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
+"checksum backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)" = "1a13fc43f04daf08ab4f71e3d27e1fc27fc437d3e95ac0063a796d92fb40f39b"
"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
@@ -1425,7 +1426,7 @@ dependencies = [
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425"
"checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed"
-"checksum mio 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "049ba5ca2b63e837adeee724aa9e36b408ed593529dcc802aa96ca14bd329bdf"
+"checksum mio 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "9fbe95ae9216d99c944a1afa429fef2a2ed012b65b0840de5047a86a82969502"
"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum muldiv 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1cbef5aa2e8cd82a18cc20e26434cc9843e1ef46e55bfabe5bddb022236c5b3e"
@@ -1435,11 +1436,11 @@ dependencies = [
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
"checksum notify 4.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "3572d71f13ea8ed41867accd971fd564aa75934cf7a1fae03ddb8c74a8a49943"
"checksum num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eafd0b45c5537c3ba526f79d3e75120036502bebacbb3f3220914067ce39dbf2"
-"checksum num-integer 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "8b8af8caa3184078cd419b430ff93684cb13937970fcb7639f728992f33ce674"
-"checksum num-iter 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "50b7cf973f09f27829571927831972c92bfd29de7a5a0148380afd12acf6d124"
+"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
+"checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e"
"checksum num-rational 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e"
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
-"checksum num-traits 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d9c79c952a4a139f44a0fe205c4ee66ce239c0e6ce72cd935f5f7e2f717549dd"
+"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
diff --git a/Cargo.toml b/Cargo.toml
index cf1acdc..2da5555 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,6 +34,7 @@ async_value = "0.2"
osstrtools = "0.1"
pathbuftools = "0.1"
clap = "2.33"
+mime = "0.3.13"
diff --git a/README.md b/README.md
index 8b72c10..719e64a 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,9 @@ hunter
![hunter](https://raw.githubusercontent.com/rabite0/hunter-stuff/master/player.png)
+***NEW***
+ * [Quick Actions] Run specific actions based on file type
+
hunter is a fast and lag-free file browser/manager for the terminal. It features a heavily asynchronous and multi-threaded design and all disk IO happens off the main thread in a non-blocking fashion, so that hunter will always stay responsive, even under heavy load on a slow spinning rust disk, even with all the previews enabled.
It's heavily inspired by the excellent ranger, but a little more Emacs-flavoured, and written in Rust to make sure it starts up quickly and to take advantage of its strong guarantees around concurrency. It's so fast I actually built in animations for some parts as a joke, but in fact it turned out to look really nice and makes it look much smoother. YMMV, of course, and this can be disabled.
@@ -13,6 +16,8 @@ To speed up the loading of directories metadata in the preview/backview is only
Technically hunter is not a file "manager" itself. It has no built in primitives for file manipulation like delete, rename, move, and so on. Instead it relies on its easy and extensive integration with the standard cli tools to do its job. For that purpose there are various file name/path substitution patterns and an auto-completing for executables you want to run.
+It also features a "quick action" mode in which you can execute customizable actions based on the file's MIME type. These can be shell-scripts or other executables. It's possible to to make hunter ask for input before these are run. The input will be put in an environment variable for the process to use. For example, you can select a few files, run a "create archive" action and you will be asked for a name for the resulting archive. You can find a more detailed explanation below.
+
This is a young project and probably (definitely) has some bugs and edge cases. It hasn't been tested on a lot of terminals, but at least alacritty, kitty and urxvt work fine. It should work on most Unix-flavoured systems supported by Rust, but was only tested on GNU/Linux. I haven't lost any files so far, at least.
A big thanks to ranger and its developers. Without its inspiration this wouldn't have been possible. hunter is not a drop-in replacement and doesn't cover every use-care, especially if you're into advanced customization, since hunter has basically none unless you modify the code, but if you just need fast above all else it might be a good choice.
@@ -107,6 +112,21 @@ media_autostart=off
media_mute=off
```
+## Quick Actions
+These are executables you can run by pressing ```a```. Which actions you can see depends on the MIME type of the files you have selected. If you have multiple files selected, hunter will try to use the most specific MIME type possible. For example, if you have selected a bunch of images with different types you will see actions for "image/*". You can see the computed MIME type in the header bar.
+
+There are "universal", "base-type", and "sub-type" actions. These are stored in ~/.config/hunter/actions/<base-type>/<sub-type>/. Universal actions are always available. These are stored right in the "actions" directory. "Base-type" actions are stored in directories like "text", "image", "video". These correspond to the part left of the "/" in a full MIME-type like "image/png". These will be available to all "text", "image", or "video" files. This list is not exhaustive, there are a lot more base-types. In addition to that you can create a directory in those base-type directories to store "sub-type" actions, which are only available to a specific file type..
+
+For example, if you want to define an action only available to PNG images, you can store that in "~/.config/hunter/actions/image/png/custom_pngcrush.sh".
+
+You can also ask for input before those actions are run. This input will be entered through hunter's minibuffer. To ask for input append "?question" to the file name, but before the extension. hunter will then set an environment variable named after whatever you put after the question mark. You can also ask for multiple things to be entered.
+
+For example, you could name an action "download_stuff?url?destination.sh". hunter will ask for the "url" and the "destination" before running your script. The values will be available through the $url and $destination environment variables.
+
+You can also make the action run in the foreground, so that it will take over the terminal while it runs. To do that simply append "!" to the file name before the extension. It should look like this: "action?query1?query2!.sh". This will ask two questions and then run the script in the foreground until it quits.
+
+There are a few examples in extras/actions. You can copy the whole directory into ~/.config/hunter/ and try it out.
+
## Startup options
You can set a few options when hunter starts. These override the configuration file. You can also tell hunter to start in a certain directory.
@@ -175,6 +195,7 @@ By default hunter uses vi-style keybindings. If you use a QWERTY-like keyboard l
| m | add bookmark |
| w | show processes |
| g holy(l) | show log |
+| a | show quick actions |
| z | open subshell in cwd |
| c | toggle columns |
| F(n) | switch to tab |
diff --git a/extra/actions/application/extract.sh b/extra/actions/application/extract.sh
new file mode 100755
index 0000000..51c8c0f
--- /dev/null
+++ b/extra/actions/application/extract.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+which 7z >/dev/null && EXTRACTOR="7z x"
+# Prefer aunpack
+which aunpack >/dev/null && EXTRACTOR=aunpack
+
+
+for file in "$@"; do
+ echo $EXTRACTOR "$file";
+done
diff --git a/extra/actions/compress?archive_name.sh b/extra/actions/compress?archive_name.sh
new file mode 100755
index 0000000..17c0d6a
--- /dev/null
+++ b/extra/actions/compress?archive_name.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z a $archive_name "$@"
diff --git a/extra/actions/synchtop!.sh b/extra/actions/synchtop!.sh
new file mode 100755
index 0000000..5e1f9f7
--- /dev/null
+++ b/extra/actions/synchtop!.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec htop
diff --git a/extra/actions/text/firefox.sh b/extra/actions/text/firefox.sh
new file mode 100755
index 0000000..a03ee81
--- /dev/null
+++ b/extra/actions/text/firefox.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+firefox "$@"
diff --git a/extra/actions/text/nano!.sh b/extra/actions/text/nano!.sh
new file mode 100755
index 0000000..2b03d6c
--- /dev/null
+++ b/extra/actions/text/nano!.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+nano "$@"
diff --git a/extra/actions/video/mpv.sh b/extra/actions/video/mpv.sh
new file mode 100755
index 0000000..87da718
--- /dev/null
+++ b/extra/actions/video/mpv.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec mpv "$@"
diff --git a/extra/actions/youtube_music?url.sh b/extra/actions/youtube_music?url.sh
new file mode 100755
index 0000000..8881499
--- /dev/null
+++ b/extra/actions/youtube_music?url.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+FORMATS=`youtube-dl -F "$url"`
+
+echo $FORMATS
+
+echo $FORMATS | grep "251 " &&
+ youtube-dl -x -f 251 "$url" &&
+ exit 0
+
+echo $FORMATS | grep "171 " &&
+ youtube-dl -x -f 171 "$url" &&
+ exit 0
+
+exit 1
diff --git a/src/file_browser.rs b/src/file_browser.rs
index ad15d01..b8d15dd 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -468,6 +468,7 @@ impl FileBrowser {
cmd: OsString::from(file.strip_prefix(&cwd)),
short_cmd: None,
args: None,
+ vars: None,
cwd: cwd.clone(),
cwd_files: None,
tab_files: None,
@@ -1084,6 +1085,7 @@ impl FileBrowser {
cmd: OsString::from(cmd),
short_cmd: None,
args: None,
+ vars: None,
cwd: cwd,
cwd_files: cwd_files,
tab_files: Some(tab_files),
@@ -1135,6 +1137,22 @@ impl FileBrowser {
Ok(())
}
+ pub fn quick_action(&self) -> HResult<()> {
+ let files = self.selected_files()?;
+ let files = if files.len() > 0 { files }
+ else { vec![self.selected_file()?.clone()] };
+
+ let sender = self.core.get_sender();
+ let core = self.preview_widget()?.get_core()?.clone();
+ let proc_view = self.proc_view.clone();
+
+ crate::quick_actions::open(files,
+ sender,
+ core,
+ proc_view)?;
+ Ok(())
+ }
+
pub fn get_footer(&self) -> HResult<String> {
let xsize = self.get_coordinates()?.xsize();
let ypos = self.get_coordinates()?.position().y();
@@ -1263,6 +1281,7 @@ impl Widget for FileBrowser {
fn on_key(&mut self, key: Key) -> HResult<()> {
match key {
+ Key::Char('a') => self.quick_action()?,
Key::Char(']') => self.move_down_left_widget()?,
Key::Char('[') => self.move_up_left_widget()?,
Key::Alt(' ') => self.external_select()?,
diff --git a/src/foldview.rs b/src/foldview.rs
index b060bb5..84dad2b 100644
--- a/src/foldview.rs
+++ b/src/foldview.rs
@@ -21,7 +21,7 @@ pub struct LogEntry {
impl Foldable for LogEntry {
- fn description(&self) -> &String {
+ fn description(&self) -> &str {
&self.description
}
fn content(&self) -> Option<&String> {
@@ -87,6 +87,8 @@ pub trait FoldableWidgetExt {
fn on_refresh(&mut self) -> HResult<()> { Ok(()) }
fn render_header(&self) -> HResult<String> { Ok("".to_string()) }
fn render_footer(&self) -> HResult<String> { Ok("".to_string()) }
+ fn on_key(&mut self, _key: Key) -> HResult<()> { Ok(()) }
+ fn render(&self) -> Vec<String> { vec![] }
}
impl FoldableWidgetExt for ListView<Vec<LogEntry>> {
@@ -162,16 +164,18 @@ impl LogList for Vec<LogEntry> {
pub trait Foldable {
- fn description(&self) -> &String;
+ fn description(&self) -> &str;
fn content(&self) -> Option<&String>;
fn lines(&self) -> usize;
fn toggle_fold(&mut self);
fn is_folded(&self) -> bool;
- fn text(&self) -> &String {
+ fn text(&self) -> &str {
if !self.is_folded() && self.content().is_some() {
self.content().unwrap()
- } else { self.description() }
+ } else {
+ &self.description()
+ }
}
fn render_description(&self) -> String {
@@ -200,7 +204,7 @@ impl<F: Foldable> ListView<Vec<F>>
where
ListView<Vec<F>>: FoldableWidgetExt {
- fn toggle_fold(&mut self) -> HResult<()> {
+ pub fn toggle_fold(&mut self) -> HResult<()> {
let fold = self.current_fold()?;
let fold_pos = self.fold_start_pos(fold);
@@ -214,7 +218,7 @@ where
Ok(())
}
- fn fold_start_pos(&self, fold: usize) -> usize {
+ pub fn fold_start_pos(&self, fold: usize) -> usize {
self.content
.iter()
.take(fold)
@@ -223,7 +227,7 @@ where
})
}
- fn current_fold(&self) -> Option<usize> {
+ pub fn current_fold(&self) -> Option<usize> {
let pos = self.get_selection();
let fold_lines = self
@@ -258,6 +262,10 @@ where
}
fn render(&self) -> Vec<String> {
+ let rendering = FoldableWidgetExt::render(self);
+ // HACK to check if no custom renderer
+ if rendering.len() > 0 { return rendering; }
+
let (xsize, _) = self.core.coordinates.size_u();
self.content
.iter()
@@ -284,15 +292,18 @@ where
}
fn on_key(&mut self, key: Key) -> HResult<()> {
- match key {
- Key::Up | Key::Char('k') => self.move_up(),
- Key::Char('K') => for _ in 0..10 { self.move_up() },
- Key::Char('J') => for _ in 0..10 { self.move_down() },
- Key::Down | Key::Char('j') => self.move_down(),
- Key::Char('t') => self.toggle_fold()?,
- Key::Char('g') => self.popup_finnished()?,
- _ => {}
+ let result = FoldableWidgetExt::on_key(self, key);
+ if let Err(HError::WidgetUndefinedKeyError{key}) = result {
+ match key {
+ Key::Up | Key::Char('k') => self.move_up(),
+ Key::Char('K') => for _ in 0..10 { self.move_up() },
+ Key::Char('J') => for _ in 0..10 { self.move_down() },
+ Key::Down | Key::Char('j') => self.move_down(),
+ Key::Char('t') => self.toggle_fold()?,
+ Key::Char('g') => self.popup_finnished()?,
+ _ => { HError::undefined_key(key)?; },
+ }
}
- Ok(())
+ result
}
}
diff --git a/src/hbox.rs b/src/hbox.rs
index d85bc51..edc8e4e 100644
--- a/src/hbox.rs
+++ b/src/hbox.rs
@@ -4,7 +4,7 @@ use crate::widget::{Widget, WidgetCore};
use crate::coordinates::{Coordinates, Size, Position};
use crate::fail::{HResult, HError, ErrorLog};
-#[derive(PartialEq)]
+#[derive(Debug, PartialEq)]
pub struct HBox<T: Widget> {
pub core: WidgetCore,
pub widgets: Vec<T>,
diff --git a/src/listview.rs b/src/listview.rs
index 62e6ace..1a9ea76 100644
--- a/src/listview.rs
+++ b/src/listview.rs
@@ -96,7 +96,7 @@ impl Listable for ListView<Files> {
}
}
-#[derive(PartialEq)]
+#[derive(Debug, PartialEq)]
pub struct ListView<T> where ListView<T>: Listable
{
pub content: T,
diff --git a/src/main.rs b/src/main.rs
index 0c81349..7982f93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,6 +22,7 @@ extern crate signal_notify;
extern crate tree_magic;
extern crate systemstat;
extern crate mime_guess;
+extern crate mime;
extern crate clap;
extern crate osstrtools;
@@ -55,6 +56,7 @@ mod fscache;
mod config;
mod stats;
mod icon;
+mod quick_actions;
#[cfg(feature = "img")]
mod imgview;
diff --git a/src/paths.rs b/src/paths.rs
index 68c6376..bfc7b53 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -55,3 +55,9 @@ pub fn history_path() -> HResult<PathBuf> {
history_path.push("history");
Ok(history_path)
}
+
+pub fn actions_path() -> HResult<PathBuf> {
+ let mut actions_path = hunter_path()?;
+ actions_path.push("actions");
+ Ok(actions_path)
+}
diff --git a/src/preview.rs b/src/preview.rs
index 1dbe511..3cb5da2 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -48,7 +48,7 @@ impl<W: Widget + Send + 'static> PartialEq for AsyncWidget<W> {
}
}
-
+#[derive(Debug)]
pub struct AsyncWidget<W: Widget + Send + 'static> {
pub widget: Async<W>,
core: WidgetCore
diff --git a/src/proclist.rs b/src/proclist.rs
index fca5029..7af7670 100644
--- a/src/proclist.rs
+++ b/src/proclist.rs
@@ -36,6 +36,7 @@ struct Process {
pub struct Cmd {
pub cmd: OsString,
pub args: Option<Vec<OsString>>,
+ pub vars: Option<Vec<(OsString, OsString)>>,
pub short_cmd: Option<String>,
pub cwd: File,
pub cwd_files: Option<Vec<File>>,
@@ -304,7 +305,7 @@ impl ListView<Vec<Process>> {
}
}
-#[derive(PartialEq)]
+#[derive(Debug, PartialEq)]
enum ProcViewWidgets {
List(ListView<Vec<Process>>),
TextView(AsyncWidget<TextView>),
@@ -337,6 +338,7 @@ impl Widget for ProcViewWidgets {
}
}
+#[derive(Debug)]
pub struct ProcView {
core: WidgetCore,
hbox: HBox<ProcViewWidgets>,
diff --git a/src/textview.rs b/src/textview.rs
index 0a67160..7dbf35f 100644
--- a/src/textview.rs
+++ b/src/textview.rs
@@ -6,7 +6,7 @@ use crate::widget::{Widget, WidgetCore};
use crate::fail::HResult;
use crate::dirty::Dirtyable;
-#[derive(PartialEq)]
+#[derive(Debug, PartialEq)]
pub struct TextView {
pub lines: Vec<String>,
pub core: WidgetCore,