mirror of
https://github.com/denisidoro/navi
synced 2024-11-10 14:04:17 +00:00
Remove support for alfred (#509)
This commit is contained in:
parent
86b0ab67db
commit
f8adffd3ff
18 changed files with 11 additions and 1352 deletions
18
.github/workflows/cd.yml
vendored
18
.github/workflows/cd.yml
vendored
|
@ -7,24 +7,6 @@ on:
|
|||
|
||||
jobs:
|
||||
|
||||
alfred:
|
||||
name: Publish Alfred workflow
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Zip
|
||||
run: scripts/action workflow
|
||||
- name: Get the version
|
||||
id: get_version
|
||||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
- name: Upload workflow to release
|
||||
uses: svenstaro/upload-release-action@v1-release
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: target/workflow/navi.zip
|
||||
tag: ${{ github.ref }}
|
||||
asset_name: navi-${{ steps.get_version.outputs.VERSION }}.alfredworkflow
|
||||
|
||||
binary:
|
||||
name: Publish ${{ matrix.target }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -308,7 +308,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "navi"
|
||||
version = "2.15.1"
|
||||
version = "2.16.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "navi"
|
||||
version = "2.15.1"
|
||||
version = "2.16.0"
|
||||
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
|
||||
edition = "2018"
|
||||
description = "An interactive cheatsheet tool for the command-line"
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
source "${HOME}/.bashrc"
|
||||
export PATH="/usr/local/bin:$PATH"
|
||||
|
||||
if [ -n "${snippet:-}" ]; then
|
||||
echo -n "$(navi alfred check)"
|
||||
else
|
||||
echo -n "__start"
|
||||
fi
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
source "${HOME}/.bashrc"
|
||||
export PATH="/usr/local/bin:$PATH"
|
||||
|
||||
_hack() {
|
||||
sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g'
|
||||
}
|
||||
|
||||
if [ -n "${snippet:-}" ]; then
|
||||
navi alfred suggestions | _hack
|
||||
else
|
||||
navi alfred start | _hack
|
||||
fi
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
source "${HOME}/.bashrc"
|
||||
export PATH="/usr/local/bin:$PATH"
|
||||
|
||||
if [ -n "${varname:-}" ]; then
|
||||
echo -n "$(navi alfred transform)" | tr -d '\n'
|
||||
else
|
||||
echo -n "$snippet"
|
||||
fi
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
case "${snippet:-}" in
|
||||
*docker*|*osascript*|*Finder*|*open*) exit 0 ;;
|
||||
esac
|
||||
|
||||
printf "terminal"
|
BIN
alfred/icon.png
BIN
alfred/icon.png
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
1039
alfred/info.plist
1039
alfred/info.plist
File diff suppressed because it is too large
Load diff
|
@ -5,9 +5,14 @@ This is *experimental*. If you face any issues, please report [here](https://git
|
|||
|
||||
![Alfred demo](https://user-images.githubusercontent.com/3226564/80294838-582b1b00-8743-11ea-9eb5-a335d8eed833.gif)
|
||||
|
||||
### Note
|
||||
|
||||
Support for alfred has been been removed. The latest version which has some support for it is [2.15.1](https://github.com/denisidoro/navi/releases/tag/v2.15.1).
|
||||
|
||||
|
||||
### Instructions
|
||||
|
||||
- make sure you have [Alfred Powerpack](https://www.alfredapp.com/powerpack/)
|
||||
- make sure **navi** is up to date
|
||||
- make sure **navi** [2.15.1](https://github.com/denisidoro/navi/releases/tag/v2.15.1) is installed
|
||||
- make sure that the `navi` binary is in the `$PATH` determined by `~/.bashrc`
|
||||
- download and install the `.alfredworkflow` for the [latest release](https://github.com/denisidoro/navi/releases/latest)
|
||||
- download and install the [latest .alfredworkflow available](https://github.com/denisidoro/navi/releases/tag/v2.15.1)
|
||||
|
|
|
@ -97,27 +97,10 @@ _ls() {
|
|||
ls -la "$@" || true
|
||||
}
|
||||
|
||||
workflow() {
|
||||
|
||||
WORKFLOW_DIR="${NAVI_HOME}/target/workflow"
|
||||
|
||||
cd "$NAVI_HOME"
|
||||
|
||||
rm -rf "${NAVI_HOME}/target" 2> /dev/null || true
|
||||
|
||||
mkdir -p "$WORKFLOW_DIR" 2> /dev/null || true
|
||||
|
||||
cp ${NAVI_HOME}/alfred/* "$WORKFLOW_DIR"
|
||||
cd "$WORKFLOW_DIR"
|
||||
zip -j -r navi.zip *
|
||||
|
||||
}
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
case "$cmd" in
|
||||
"release") release "$@" ;;
|
||||
"workflow") workflow "$@" ;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
|
|
|
@ -20,7 +20,5 @@ cargo clippy || true
|
|||
|
||||
header "dot code beautify..."
|
||||
find scripts -type f | xargs -I% dot code beautify % || true
|
||||
dot code beautify "${NAVI_HOME}/alfred/alfred.bash" || true
|
||||
dot code beautify "${NAVI_HOME}/alfred/alfred2.bash" || true
|
||||
dot code beautify "${NAVI_HOME}/tests/core.bash" || true
|
||||
dot code beautify "${NAVI_HOME}/tests/run" || true
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
use crate::env_var;
|
||||
use crate::filesystem;
|
||||
use crate::shell::BashSpawnError;
|
||||
use crate::structures::cheat::Suggestion;
|
||||
use crate::structures::config::Config;
|
||||
use crate::structures::fetcher::Fetcher;
|
||||
use crate::writer;
|
||||
use anyhow::Context;
|
||||
use anyhow::Error;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
pub fn main(config: Config) -> Result<(), Error> {
|
||||
let mut child = Command::new("cat")
|
||||
.stdin(Stdio::piped())
|
||||
.spawn()
|
||||
.context("Unable to create child")?;
|
||||
let stdin = child.stdin.as_mut().context("Unable to get stdin")?;
|
||||
let mut writer = writer::alfred::Writer::new();
|
||||
|
||||
writer::alfred::print_items_start(None);
|
||||
|
||||
let fetcher = filesystem::Fetcher::new(config.path, None);
|
||||
fetcher
|
||||
.fetch(stdin, &mut writer, &mut Vec::new())
|
||||
.context("Failed to parse variables intended for finder")?;
|
||||
|
||||
// make sure everything was printed to stdout before attempting to close the items vector
|
||||
let _ = child.wait_with_output().context("Failed to wait for fzf")?;
|
||||
|
||||
writer::alfred::print_items_end();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prompt_finder(suggestion: &Suggestion) -> Result<String, Error> {
|
||||
let (suggestion_command, _suggestion_opts) = suggestion;
|
||||
|
||||
let child = Command::new("bash")
|
||||
.stdout(Stdio::piped())
|
||||
.arg("-c")
|
||||
.arg(&suggestion_command)
|
||||
.spawn()
|
||||
.map_err(|e| BashSpawnError::new(suggestion_command, e))?;
|
||||
|
||||
let suggestions = String::from_utf8(
|
||||
child
|
||||
.wait_with_output()
|
||||
.context("Failed to wait and collect output from bash")?
|
||||
.stdout,
|
||||
)
|
||||
.context("Suggestions are invalid utf8")?;
|
||||
|
||||
Ok(suggestions)
|
||||
}
|
||||
|
||||
pub fn suggestions(config: Config, dry_run: bool) -> Result<(), Error> {
|
||||
let mut child = Command::new("cat")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::null())
|
||||
.spawn()
|
||||
.context("Unable to create child")?;
|
||||
let stdin = child.stdin.as_mut().context("Unable to get stdin")?;
|
||||
let mut writer = writer::alfred::Writer::new();
|
||||
|
||||
let fetcher = filesystem::Fetcher::new(config.path, None);
|
||||
let variables = fetcher
|
||||
.fetch(stdin, &mut writer, &mut Vec::new())
|
||||
.context("Failed to parse variables intended for finder")?
|
||||
.expect("Empty variable map");
|
||||
|
||||
let tags = env_var::get("tags").context(r#"The env var "tags" isn't set"#)?;
|
||||
let snippet = env_var::get("snippet").context(r#"The env var "snippet" isn't set"#)?;
|
||||
|
||||
let capture = writer::VAR_REGEX.captures_iter(&snippet).next();
|
||||
let bracketed_varname = &(capture.expect("Invalid capture"))[0];
|
||||
let varname = &bracketed_varname[1..bracketed_varname.len() - 1];
|
||||
let command = variables.get_suggestion(&tags, &varname);
|
||||
|
||||
if dry_run {
|
||||
if command.is_none() {
|
||||
println!("{}", varname);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
writer::alfred::print_items_start(Some(varname));
|
||||
|
||||
let command = command.context("Invalid command")?;
|
||||
let lines = prompt_finder(command).context("Invalid lines")?;
|
||||
|
||||
writer.reset();
|
||||
|
||||
for line in lines.split('\n') {
|
||||
writer.write_suggestion(&snippet, &varname, &line);
|
||||
}
|
||||
|
||||
writer::alfred::print_items_end();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn transform() -> Result<(), Error> {
|
||||
let snippet = env_var::get("snippet").context(r#"The env var "snippet" isn't set"#)?;
|
||||
let varname = env_var::get("varname").context(r#"The env var "varname" isn't set"#)?;
|
||||
let value = if let Ok(v) = env_var::get(&varname) {
|
||||
v
|
||||
} else {
|
||||
env_var::get("free").context("The env var for varname isn't set")?
|
||||
};
|
||||
|
||||
let bracketed_varname = format!("<{}>", varname);
|
||||
let interpolated_snippet = snippet.replace(&bracketed_varname, &value);
|
||||
println!("{}", interpolated_snippet);
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
pub mod alfred;
|
||||
pub mod core;
|
||||
pub mod func;
|
||||
pub mod info;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::cmds;
|
||||
use crate::structures::config::Command::{Alfred, Fn, Info, Preview, PreviewVar, Repo, Widget};
|
||||
use crate::structures::config::{AlfredCommand, Config, RepoCommand};
|
||||
use crate::structures::config::Command::{Fn, Info, Preview, PreviewVar, Repo, Widget};
|
||||
use crate::structures::config::{Config, RepoCommand};
|
||||
use anyhow::Context;
|
||||
use anyhow::Error;
|
||||
|
||||
|
@ -38,20 +38,6 @@ pub fn handle_config(config: Config) -> Result<(), Error> {
|
|||
}
|
||||
},
|
||||
|
||||
Alfred { cmd } => match cmd {
|
||||
AlfredCommand::Start => {
|
||||
cmds::alfred::main(config).context("Failed to call Alfred starting function")
|
||||
}
|
||||
AlfredCommand::Suggestions => cmds::alfred::suggestions(config, false)
|
||||
.context("Failed to call Alfred suggestion function"),
|
||||
AlfredCommand::Check => {
|
||||
cmds::alfred::suggestions(config, true).context("Failed to call Alfred check function")
|
||||
}
|
||||
AlfredCommand::Transform => {
|
||||
cmds::alfred::transform().context("Failed to call Alfred transform function")
|
||||
}
|
||||
},
|
||||
|
||||
_ => cmds::core::main(config),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -194,12 +194,6 @@ pub enum Command {
|
|||
#[clap(possible_values = INFO_POSSIBLE_VALUES, case_insensitive = true)]
|
||||
info: Info,
|
||||
},
|
||||
/// Helper command for Alfred integration
|
||||
#[clap(setting = AppSettings::Hidden)]
|
||||
Alfred {
|
||||
#[clap(subcommand)]
|
||||
cmd: AlfredCommand,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap)]
|
||||
|
@ -213,18 +207,6 @@ pub enum RepoCommand {
|
|||
Browse,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clap)]
|
||||
pub enum AlfredCommand {
|
||||
/// Outputs a JSON with commands
|
||||
Start,
|
||||
/// Outputs a JSON with variable suggestions
|
||||
Suggestions,
|
||||
/// Transforms the snippet env var with the selected value
|
||||
Transform,
|
||||
/// Checks whether to use free input
|
||||
Check,
|
||||
}
|
||||
|
||||
pub enum Source {
|
||||
Filesystem(Option<String>, Option<String>),
|
||||
Tldr(String),
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
use crate::structures::item::Item;
|
||||
use crate::writer;
|
||||
|
||||
pub struct Writer {
|
||||
is_first: bool,
|
||||
}
|
||||
|
||||
fn escape_for_json(txt: &str) -> String {
|
||||
txt.replace('\\', "\\\\")
|
||||
.replace('"', "“")
|
||||
.replace(writer::NEWLINE_ESCAPE_CHAR, " ")
|
||||
}
|
||||
|
||||
pub fn print_items_start(varname: Option<&str>) {
|
||||
print!("{{");
|
||||
|
||||
if let Some(v) = varname {
|
||||
print!(r#""variables": {{"varname": "{varname}"}},"#, varname = v);
|
||||
}
|
||||
|
||||
println!(r#""items": ["#);
|
||||
}
|
||||
|
||||
pub fn print_items_end() {
|
||||
println!(r#"]}}"#);
|
||||
}
|
||||
|
||||
impl writer::Writer for Writer {
|
||||
fn write(&mut self, item: &Item) -> String {
|
||||
let prefix = if self.is_first {
|
||||
self.is_first = false;
|
||||
""
|
||||
} else {
|
||||
","
|
||||
};
|
||||
|
||||
let tags = escape_for_json(&item.tags);
|
||||
let comment = escape_for_json(&item.comment);
|
||||
let snippet = escape_for_json(&item.snippet);
|
||||
|
||||
format!(
|
||||
r#"{prefix}{{"type":"file","title":"{comment}","match":"{comment} {tags} {snippet}","subtitle":"{tags} :: {snippet}","variables":{{"tags":"{tags}","comment":"{comment}","snippet":"{snippet}"}},"icon":{{"path":"icon.png"}}}}"#,
|
||||
prefix = prefix,
|
||||
tags = tags,
|
||||
comment = comment,
|
||||
snippet = snippet
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Writer {
|
||||
pub fn new() -> Writer {
|
||||
Writer { is_first: true }
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.is_first = true
|
||||
}
|
||||
|
||||
pub fn write_suggestion(&mut self, snippet: &str, varname: &str, line: &str) {
|
||||
if line.len() < 3 {
|
||||
return;
|
||||
}
|
||||
|
||||
let prefix = if self.is_first {
|
||||
self.is_first = false;
|
||||
""
|
||||
} else {
|
||||
","
|
||||
};
|
||||
|
||||
println!(
|
||||
r#"{prefix}{{"title":"{value}","subtitle":"{snippet}","variables":{{"{varname}":"{value}"}},"icon":{{"path":"icon.png"}}}}"#,
|
||||
prefix = prefix,
|
||||
snippet = snippet,
|
||||
varname = varname,
|
||||
value = line
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
pub mod alfred;
|
||||
pub mod terminal;
|
||||
|
||||
use crate::structures::item::Item;
|
||||
|
|
Loading…
Reference in a new issue