mirror of https://github.com/bobwen-dev/hunter
added auto-installer for configs
This commit is contained in:
parent
89260e4312
commit
fc32c58c9d
|
@ -0,0 +1,7 @@
|
|||
animation=on
|
||||
show_hidden=off
|
||||
select_cmd=find -type f | fzf -m
|
||||
cd_cmd=find -type d | fzf
|
||||
icons=off
|
||||
media_autostart=off
|
||||
media_mute=off
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z -l -p -- "${1}"
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
w3m -dump "${1}" ||
|
||||
links -dump "${1}" ||
|
||||
elinks -dump "${1}" ||
|
||||
lynx -dump "${1}"
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
w3m -dump ||
|
||||
elinks -dump ||
|
||||
links -dump ||
|
||||
lynx -dump
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
odt2text "${1}" 2> /dev/null
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
pdftotext -l 10 -layout -nopgbrk -q "${1}" -||
|
||||
mutool draw -F txt -i -- "${1}" ||
|
||||
exiftool "${1}" 2> /dev/null
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
pdftotext -l 10 -layout -nopgbrk -q "${1}" - 2> /dev/null ||
|
||||
mutool draw -F txt -i -- "${FILE_PATH}" 1-10 2> /dev/null ||
|
||||
exiftool "${FILE_PATH}" 2> /dev/null
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
bat --plain --color=always --paging=never "${1}" --line-range 1:100 --tabs 8
|
||||
2>/dev/null && exit 5
|
||||
|
||||
highlight --replace-tabs=4 --force -- "${1}"
|
||||
2>/dev/null && exit 5
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
pdftotext -l 10 -layout -nopgbrk -q "${1}" -||
|
||||
mutool draw -F txt -i -- "${1}" ||
|
||||
exiftool "${1}" 2> /dev/null
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
7z l -p -- "${1}"
|
217
extra/scope.sh
217
extra/scope.sh
|
@ -1,217 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o noclobber -o noglob -o nounset -o pipefail
|
||||
IFS=$'\n'
|
||||
|
||||
# If the option `use_preview_script` is set to `true`,
|
||||
# then this script will be called and its output will be displayed in ranger.
|
||||
# ANSI color codes are supported.
|
||||
# STDIN is disabled, so interactive scripts won't work properly
|
||||
|
||||
# This script is considered a configuration file and must be updated manually.
|
||||
# It will be left untouched if you upgrade ranger.
|
||||
|
||||
# Meanings of exit codes:
|
||||
# code | meaning | action of ranger
|
||||
# -----+------------+-------------------------------------------
|
||||
# 0 | success | Display stdout as preview
|
||||
# 1 | no preview | Display no preview at all
|
||||
# 2 | plain text | Display the plain content of the file
|
||||
# 3 | fix width | Don't reload when width changes
|
||||
# 4 | fix height | Don't reload when height changes
|
||||
# 5 | fix both | Don't ever reload
|
||||
# 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview
|
||||
# 7 | image | Display the file directly as an image
|
||||
|
||||
# Script arguments
|
||||
FILE_PATH="${1}" # Full path of the highlighted file
|
||||
PV_WIDTH="${2}" # Width of the preview pane (number of fitting characters)
|
||||
PV_HEIGHT="${3}" # Height of the preview pane (number of fitting characters)
|
||||
IMAGE_CACHE_PATH="${4}" # Full path that should be used to cache image preview
|
||||
PV_IMAGE_ENABLED="${5}" # 'True' if image previews are enabled, 'False' otherwise.
|
||||
|
||||
FILE_EXTENSION="${FILE_PATH##*.}"
|
||||
FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Settings
|
||||
HIGHLIGHT_SIZE_MAX=262143 # 256KiB
|
||||
HIGHLIGHT_TABWIDTH=8
|
||||
HIGHLIGHT_STYLE='pablo'
|
||||
PYGMENTIZE_STYLE='autumn'
|
||||
|
||||
|
||||
handle_extension() {
|
||||
case "${FILE_EXTENSION_LOWER}" in
|
||||
# Archive
|
||||
a|ace|bz2|xz|gz|alz|arc|arj|cab|cpio|deb|jar|lha|lz|lzh|lzma|lzo|\
|
||||
rpm|rz|t7z|tar|tlz|txz|tZ|tzo|war|xpi|Z|zip)
|
||||
7z l -p -- "${FILE_PATH}" && exit 5
|
||||
#atool --list -- "${FILE_PATH}" && exit 5
|
||||
#bsdtar --list --file "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
rar)
|
||||
# Avoid password prompt by providing empty password
|
||||
unrar lt -p- -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
7z)
|
||||
# Avoid password prompt by providing empty password
|
||||
7z l -p -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
# PDF
|
||||
pdf)
|
||||
# Preview as text conversion
|
||||
pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w ${PV_WIDTH} && exit 5
|
||||
mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w ${PV_WIDTH} && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
# BitTorrent
|
||||
torrent)
|
||||
transmission-show -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
# OpenDocument
|
||||
odt|ods|odp|sxw)
|
||||
# Preview as text conversion
|
||||
odt2txt "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
# HTML
|
||||
htm|html|xhtml)
|
||||
# Preview as text conversion
|
||||
w3m -dump "${FILE_PATH}" && exit 5
|
||||
lynx -dump -- "${FILE_PATH}" && exit 5
|
||||
elinks -dump "${FILE_PATH}" && exit 5
|
||||
;; # Continue with next handler on failure
|
||||
esac
|
||||
}
|
||||
|
||||
handle_image() {
|
||||
local mimetype="${1}"
|
||||
case "${mimetype}" in
|
||||
# SVG
|
||||
# image/svg+xml)
|
||||
# convert "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# exit 1;;
|
||||
|
||||
# Image
|
||||
image/*)
|
||||
local orientation
|
||||
orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FILE_PATH}" )"
|
||||
# If orientation data is present and the image actually
|
||||
# needs rotating ("1" means no rotation)...
|
||||
if [[ -n "$orientation" && "$orientation" != 1 ]]; then
|
||||
# ...auto-rotate the image according to the EXIF data.
|
||||
convert -- "${FILE_PATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
|
||||
fi
|
||||
|
||||
# `w3mimgdisplay` will be called for all images (unless overriden as above),
|
||||
# but might fail for unsupported types.
|
||||
exit 7;;
|
||||
|
||||
# Video
|
||||
# video/*)
|
||||
# # Thumbnail
|
||||
# ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
|
||||
# exit 1;;
|
||||
# PDF
|
||||
# application/pdf)
|
||||
# pdftoppm -f 1 -l 1 \
|
||||
# -scale-to-x 1920 \
|
||||
# -scale-to-y -1 \
|
||||
# -singlefile \
|
||||
# -jpeg -tiffcompression jpeg \
|
||||
# -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
|
||||
# && exit 6 || exit 1;;
|
||||
|
||||
# Preview archives using the first image inside.
|
||||
# (Very useful for comic book collections for example.)
|
||||
# application/zip|application/x-rar|application/x-7z-compressed|\
|
||||
# application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar)
|
||||
# local fn=""; local fe=""
|
||||
# local zip=""; local rar=""; local tar=""; local bsd=""
|
||||
# case "${mimetype}" in
|
||||
# application/zip) zip=1 ;;
|
||||
# application/x-rar) rar=1 ;;
|
||||
# application/x-7z-compressed) ;;
|
||||
# *) tar=1 ;;
|
||||
# esac
|
||||
# { [ "$tar" ] && fn=$(tar --list --file "${FILE_PATH}"); } || \
|
||||
# { fn=$(bsdtar --list --file "${FILE_PATH}") && bsd=1 && tar=""; } || \
|
||||
# { [ "$rar" ] && fn=$(unrar lb -p- -- "${FILE_PATH}"); } || \
|
||||
# { [ "$zip" ] && fn=$(zipinfo -1 -- "${FILE_PATH}"); } || return
|
||||
#
|
||||
# fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \
|
||||
# [ print(l, end='') for l in sys.stdin if \
|
||||
# (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\
|
||||
# sort -V | head -n 1)
|
||||
# [ "$fn" = "" ] && return
|
||||
# [ "$bsd" ] && fn=$(printf '%b' "$fn")
|
||||
#
|
||||
# [ "$tar" ] && tar --extract --to-stdout \
|
||||
# --file "${FILE_PATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g')
|
||||
# [ "$bsd" ] && bsdtar --extract --to-stdout \
|
||||
# --file "${FILE_PATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}"
|
||||
# [ "$rar" ] && unrar p -p- -inul -- "${FILE_PATH}" "$fn" > \
|
||||
# "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# [ "$zip" ] && unzip -pP "" -- "${FILE_PATH}" "$fe" > \
|
||||
# "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
|
||||
# ;;
|
||||
esac
|
||||
}
|
||||
|
||||
handle_mime() {
|
||||
local mimetype="${1}"
|
||||
case "${mimetype}" in
|
||||
# Text
|
||||
text/* | */xml)
|
||||
# Syntax highlight
|
||||
if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$( tput colors )" -ge 256 ]]; then
|
||||
local pygmentize_format='terminal256'
|
||||
local highlight_format='xterm256'
|
||||
else
|
||||
local pygmentize_format='terminal'
|
||||
local highlight_format='ansi'
|
||||
fi
|
||||
highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \
|
||||
--style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" && exit 5
|
||||
# pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5
|
||||
exit 2;;
|
||||
|
||||
# Image
|
||||
image/*)
|
||||
# Preview as text conversion
|
||||
# img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
# Video and audio
|
||||
video/* | audio/*)
|
||||
mediainfo "${FILE_PATH}" && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
esac
|
||||
}
|
||||
|
||||
handle_fallback() {
|
||||
echo '----- File Type Classification -----' && file --dereference --brief -- "${FILE_PATH}" && exit 5
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )"
|
||||
if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then
|
||||
handle_image "${MIMETYPE}"
|
||||
fi
|
||||
handle_extension
|
||||
handle_mime "${MIMETYPE}"
|
||||
handle_fallback
|
||||
|
||||
exit 1
|
|
@ -15,7 +15,7 @@ pub struct Bookmarks {
|
|||
impl Bookmarks {
|
||||
pub fn new() -> Bookmarks {
|
||||
let mut bm = Bookmarks { mapping: HashMap::new() };
|
||||
bm.load().log();
|
||||
bm.load().or_else(|_| HError::log("Couldn't load bookmarks!")).ok();
|
||||
bm
|
||||
}
|
||||
pub fn add(&mut self, key: char, path: &str) -> HResult<()> {
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::paths;
|
|||
|
||||
use crate::fail::{HError, HResult, ErrorLog};
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
// These are options, so we know if they have been set or not
|
||||
struct ArgvConfig {
|
||||
|
|
|
@ -104,8 +104,8 @@ pub enum HError {
|
|||
}
|
||||
|
||||
impl HError {
|
||||
pub fn log<T>(log: String) -> HResult<T> {
|
||||
Err(HError::Log(log))
|
||||
pub fn log<T>(log: &str) -> HResult<T> {
|
||||
Err(HError::Log(String::from(log))).log_and()
|
||||
}
|
||||
pub fn quit() -> HResult<()> {
|
||||
Err(HError::Quit)
|
||||
|
@ -243,7 +243,8 @@ impl From<std::io::Error> for HError {
|
|||
impl From<failure::Error> for HError {
|
||||
fn from(error: failure::Error) -> Self {
|
||||
let err = HError::Error(format!("{}", error),
|
||||
Backtrace::new_arced());
|
||||
Backtrace::new_arced()
|
||||
);
|
||||
err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,14 @@ pub struct FileBrowser {
|
|||
}
|
||||
|
||||
impl Tabbable for TabView<FileBrowser> {
|
||||
fn on_new(&mut self) -> HResult<()> {
|
||||
let core = self.core.clone();
|
||||
std::thread::spawn(move || {
|
||||
crate::config_installer::ensure_config(core).log();
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn new_tab(&mut self) -> HResult<()> {
|
||||
let cur_tab = self.active_tab_();
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ mod stats;
|
|||
mod icon;
|
||||
mod quick_actions;
|
||||
mod trait_ext;
|
||||
mod config_installer;
|
||||
|
||||
#[cfg(feature = "img")]
|
||||
mod imgview;
|
||||
|
|
|
@ -70,7 +70,7 @@ impl History {
|
|||
}
|
||||
|
||||
fn add(&mut self, htype: &str, input: &str) {
|
||||
self.load().log();
|
||||
self.load().ok();
|
||||
let history = match self.history.get_mut(htype) {
|
||||
Some(history) => history,
|
||||
None => {
|
||||
|
@ -498,7 +498,7 @@ impl Widget for MiniBuffer {
|
|||
}
|
||||
|
||||
fn after_draw(&self) -> HResult<()> {
|
||||
let cursor_pos = self.query.len() +
|
||||
let cursor_pos = crate::term::string_len(&self.query) +
|
||||
": ".len() +
|
||||
self.position;
|
||||
|
||||
|
|
|
@ -24,11 +24,9 @@ pub fn hunter_path() -> HResult<PathBuf> {
|
|||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn hunter_path() -> HResult<PathBuf> {
|
||||
dbg!("Finding path for macOS");
|
||||
let mut hunter_path = home_path()?;
|
||||
hunter_path.push(".config/");
|
||||
hunter_path.push("hunter/");
|
||||
dbg!(&hunter_path);
|
||||
Ok(hunter_path)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ pub trait Tabbable {
|
|||
}
|
||||
fn on_refresh(&mut self) -> HResult<()> { Ok(()) }
|
||||
fn on_config_loaded(&mut self) -> HResult<()> { Ok(()) }
|
||||
|
||||
fn on_new(&mut self) -> HResult<()> { Ok(()) }
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,15 @@ pub struct TabView<T> where T: Widget, TabView<T>: Tabbable {
|
|||
|
||||
impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
|
||||
pub fn new(core: &WidgetCore) -> TabView<T> {
|
||||
TabView {
|
||||
let mut tabview = TabView {
|
||||
widgets: vec![],
|
||||
active: 0,
|
||||
core: core.clone()
|
||||
}
|
||||
};
|
||||
|
||||
Tabbable::on_new(&mut tabview).log();
|
||||
|
||||
tabview
|
||||
}
|
||||
|
||||
pub fn push_widget(&mut self, widget: T) -> HResult<()> {
|
||||
|
|
11
src/term.rs
11
src/term.rs
|
@ -251,6 +251,17 @@ fn get_tokens(string: &str) -> Vec<Token> {
|
|||
tokens.0
|
||||
}
|
||||
|
||||
pub fn string_len(string: &str) -> usize {
|
||||
let tokens = get_tokens(&string);
|
||||
|
||||
tokens.iter().fold(0, |len, token| {
|
||||
match token {
|
||||
Token::Text(text) => len + text.len(),
|
||||
_ => len
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn sized_string_u(string: &str, xsize: usize) -> String {
|
||||
let tokens = get_tokens(&string);
|
||||
|
|
|
@ -75,10 +75,10 @@ impl WidgetCore {
|
|||
let (sender, receiver) = channel();
|
||||
let status_bar_content = Arc::new(Mutex::new(None));
|
||||
|
||||
let mut config = Async::new(|_| Ok(Config::load()?));
|
||||
let confsender = Arc::new(Mutex::new(sender.clone()));
|
||||
let mut config = Async::new(move |_| Ok(Config::load()?));
|
||||
let confsender = sender.clone();
|
||||
config.on_ready(move |_, _| {
|
||||
confsender.lock().map(|s| s.send(Events::ConfigLoaded)).ok();
|
||||
confsender.send(Events::ConfigLoaded).ok();
|
||||
Ok(())
|
||||
}).log();
|
||||
config.run().log();
|
||||
|
@ -123,7 +123,7 @@ impl WidgetCore {
|
|||
}
|
||||
|
||||
pub fn show_status(&self, status: &str) -> HResult<()> {
|
||||
HError::log::<()>(status.to_string()).log();
|
||||
HError::log::<()>(status).ok();
|
||||
{
|
||||
let mut status_content = self.status_bar_content.lock()?;
|
||||
*status_content = Some(status.to_string());
|
||||
|
@ -466,7 +466,7 @@ pub trait Widget {
|
|||
self.get_core()?.screen()?.clear().log();
|
||||
}
|
||||
Events::ConfigLoaded => {
|
||||
self.get_core_mut()?.config.write()?.pull_async()?;
|
||||
self.get_core_mut()?.config.write()?.pull_async().ok();
|
||||
self.config_loaded().log();
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Reference in New Issue