From 96a80f9b35f89d8f39b7eefba7ea4e083a1ab7a5 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 19 Aug 2022 17:15:17 +0300 Subject: [PATCH] shell/zsh: add fzf preview --- shell/zsh | 10 ++++++---- src/cli.rs | 10 +++++++--- src/cli/show.rs | 5 ++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/shell/zsh b/shell/zsh index 115c592..f5efe53 100644 --- a/shell/zsh +++ b/shell/zsh @@ -1,5 +1,5 @@ function __tas_task_idx() { - echo "$@" | sed 's/^\([0-9]\+\)\..\+$/\1/' + echo "$@" | sed 's/^[> ] \([0-9]\+\)\..\+$/\1/' } function __tas_show() { @@ -11,13 +11,15 @@ function __tas_start() { } function __tas_list() { - tas list | fzf --info=inline --height=50% --no-sort --keep-right --layout=reverse + tas list | fzf \ + --info=inline --height=50% --no-sort --keep-right --layout=reverse \ + --preview="tas show \$(sed 's/^[> ] \\([0-9]\\+\\)\\..\\+$/\\1/' {+f})" } function taz() { case $1 in "" | "show" | "sh") - __tas_show $(__tas_list) + __tas_show "$(__tas_list)" ;; "list" | "ls") @@ -25,7 +27,7 @@ function taz() { ;; "start" | "st") - __tas_start $(__tas_list) + __tas_start "$(__tas_list)" esac } diff --git a/src/cli.rs b/src/cli.rs index 51f2d42..4adf810 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -51,17 +51,21 @@ pub enum SubCommand { } pub fn print_task_detail(task: &domain::Task) { - print!(" "); + print_task_detail_opt(task, " ") +} + +pub fn print_task_detail_opt(task: &domain::Task, prefix: &str) { + print!("{prefix}"); if let Some(project) = task.project.as_ref() { print!("[{}]: ", project); } println!("{}", task.name); if let Some(link) = task.link.as_ref() { - println!(" link: {}", link); + println!("{prefix}link: {}", link); } if let Some(dir_path) = task.dir_path.as_ref() { - println!(" path: {}", dir_path.to_string_lossy()); + println!("{prefix}path: {}", dir_path.to_string_lossy()); } } diff --git a/src/cli/show.rs b/src/cli/show.rs index ca20359..8983757 100644 --- a/src/cli/show.rs +++ b/src/cli/show.rs @@ -16,7 +16,7 @@ use std::io::Write; use std::process::{Command, Stdio}; -use crate::cli::print_task_detail; +use crate::cli::print_task_detail_opt; use crate::domain::CurrentTaskInfo; use crate::repo::Repository; @@ -109,8 +109,7 @@ pub fn execute(repo: impl Repository, args: Args) { eprintln!("[WARNING]: You don't provide part. --clip option will ignore."); } - println!("Information about your current task:"); - print_task_detail(&task); + print_task_detail_opt(&task, ""); } Some(PrintPart::Project) => { if args.clip {