Skip to content

Commit

Permalink
Minor fixes (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Mar 11, 2020
1 parent e6b7c2f commit 06eae50
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 86 deletions.
50 changes: 25 additions & 25 deletions scripts/action
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@ source "${NAVI_HOME}/scripts/install"

release() {

TAR_DIR="${NAVI_HOME}/target/tar"
TAR_DIR="${NAVI_HOME}/target/tar"

target="${1:-}"
if [[ $target == *"osx"* ]]; then
echoerr "OSX cross-compile is impossible. Fallbacking to cargo..."
target=""
fi
target="${1:-}"
if [[ $target == *"osx"* ]]; then
echoerr "OSX cross-compile is impossible. Fallbacking to cargo..."
target=""
fi

cd "$NAVI_HOME"
cd "$NAVI_HOME"

rm -rf "${NAVI_HOME}/target" 2> /dev/null || true
rm -rf "${NAVI_HOME}/target" 2> /dev/null || true

if [ -n "$target" ]; then
cargo install cross 2> /dev/null || true
cross build --release --locked --target "$target"
bin_folder="${target}/release"
else
cargo build --release --locked
bin_folder="release"
fi
if [ -n "$target" ]; then
cargo install cross 2> /dev/null || true
cross build --release --locked --target "$target"
bin_folder="${target}/release"
else
cargo build --release --locked
bin_folder="release"
fi

bin_path="${NAVI_HOME}/target/${bin_folder}/navi"
chmod +x "$bin_path"
mkdir -p "$TAR_DIR" 2> /dev/null || true
bin_path="${NAVI_HOME}/target/${bin_folder}/navi"
chmod +x "$bin_path"
mkdir -p "$TAR_DIR" 2> /dev/null || true

cp -r "${NAVI_HOME}/cheats" "$TAR_DIR"
cp -r "${NAVI_HOME}/shell" "$TAR_DIR"
cp "$bin_path" "$TAR_DIR"
cp -r "${NAVI_HOME}/cheats" "$TAR_DIR"
cp -r "${NAVI_HOME}/shell" "$TAR_DIR"
cp "$bin_path" "$TAR_DIR"

cd "${NAVI_HOME}/target/tar"
tar -czf navi.tar.gz *
cd "${NAVI_HOME}/target/tar"
tar -czf navi.tar.gz *

}

cmd="$1"
shift

case "$cmd" in
"release") release "$@" ;;
"release") release "$@" ;;
esac
44 changes: 22 additions & 22 deletions scripts/brew
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"

gen_formula() {
version="$(latest_version_released)"
header "version: ${version}"

header "sha_for x86_64-unknown-linux-musl..."
sha_linux="$(sha_for_asset_on_github "$version" "x86_64-unknown-linux-musl")"

header "sha_for x86_64-osx..."
sha_osx="$(sha_for_asset_on_github "$version" "x86_64-osx")"

header "rb..."
curl -s https://raw.githubusercontent.com/denisidoro/homebrew-tools/master/navirs.rb \
| sed -E "s/version ['\"].*/version '${version}'/" \
| awk '!x{x=sub("sha256","sha_osx")}7' \
| awk '!x{x=sub("sha256","sha_linux")}7' \
| sed -E "s/sha_osx.*/sha256 \"${sha_osx}\"/" \
| sed -E "s/sha_linux.*/sha256 \"${sha_linux}\"/"
version="$(latest_version_released)"
header "version: ${version}"

header "sha_for x86_64-unknown-linux-musl..."
sha_linux="$(sha_for_asset_on_github "$version" "x86_64-unknown-linux-musl")"

header "sha_for x86_64-osx..."
sha_osx="$(sha_for_asset_on_github "$version" "x86_64-osx")"

header "rb..."
curl -s https://raw.githubusercontent.com/denisidoro/homebrew-tools/master/navirs.rb \
| sed -E "s/version ['\"].*/version '${version}'/" \
| awk '!x{x=sub("sha256","sha_osx")}7' \
| awk '!x{x=sub("sha256","sha_linux")}7' \
| sed -E "s/sha_osx.*/sha256 \"${sha_osx}\"/" \
| sed -E "s/sha_linux.*/sha256 \"${sha_linux}\"/"
}

gen_sha() {
version="${1:-$(latest_version_released)}"
header "version: ${version}"
version="${1:-$(latest_version_released)}"
header "version: ${version}"

header "sha_for source..."
sha_for_asset_on_github "$version"
header "sha_for source..."
sha_for_asset_on_github "$version"
}

cmd="$1"
shift

case "$cmd" in
"formula") gen_formula "$@" ;;
"sha") gen_sha "$@" ;;
"formula") gen_formula "$@" ;;
"sha") gen_sha "$@" ;;
esac
6 changes: 3 additions & 3 deletions scripts/docker
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
cd "$NAVI_HOME"

docker run \
-e HOMEBREW_NO_AUTO_UPDATE=1 \
-it linuxbrew/alpine \
bash -c 'brew install denisidoro/tools/navirs; bash'
-e HOMEBREW_NO_AUTO_UPDATE=1 \
-it linuxbrew/alpine \
bash -c 'brew install denisidoro/tools/navirs; bash'
9 changes: 9 additions & 0 deletions scripts/fix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
set -euo pipefail

export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"

header "Cargo nighly fix..."
cargo +nightly fix --clippy -Z unstable-options 2> /dev/null || true

header "Cargo fix..."
cargo fix 2> /dev/null || true

header "Cargo fmt..."
cargo fmt 2> /dev/null || true

header "dot code beautify..."
find scripts -type f | xargs -I% dot code beautify 2> /dev/null || true
22 changes: 11 additions & 11 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ latest_version_released() {
}

asset_url() {
local -r version="$1"
local -r variant="${2:-}"
if [[ -n "$variant" ]]; then
echo "https://github.com/denisidoro/navi/releases/download/v${version}/navi-${variant}.tar.gz"
else
echo "https://github.com/denisidoro/navi/archive/v${version}.tar.gz"
fi
local -r version="$1"
local -r variant="${2:-}"

if [[ -n "$variant" ]]; then
echo "https://github.com/denisidoro/navi/releases/download/v${version}/navi-${variant}.tar.gz"
else
echo "https://github.com/denisidoro/navi/archive/v${version}.tar.gz"
fi
}

download_asset() {
Expand All @@ -83,8 +83,8 @@ download_asset() {
}

sha_for_asset_on_github() {
local -r url="$(asset_url "$@")"
curl -sL "$url" | sha256 | awk '{print $1}'
local -r url="$(asset_url "$@")"
curl -sL "$url" | sha256 | awk '{print $1}'
}

get_target() {
Expand Down Expand Up @@ -132,7 +132,7 @@ install_navi() {
make install

else
no_binary_warning
no_binary_warning
echoerr "You don't have the necessary tools to build it"
echoerr "Please open an issue at https://github.com/denisidoro/navi"
echoerr "Aborting..."
Expand Down
20 changes: 10 additions & 10 deletions scripts/make
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"

install() {
export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
export BIN_DIR="${BIN_DIR:-"$(get_bin_dir)"}"
echoerr "The final binary will be available at ${BIN_DIR}/navi..."
"${NAVI_HOME}/scripts/action" release
ln -s "${NAVI_HOME}/target/tar/navi" "${BIN_DIR}/navi"
export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
export BIN_DIR="${BIN_DIR:-"$(get_bin_dir)"}"
echoerr "The final binary will be available at ${BIN_DIR}/navi..."
"${NAVI_HOME}/scripts/action" release
ln -s "${NAVI_HOME}/target/tar/navi" "${BIN_DIR}/navi"
}

uninstall() {
export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
rm -rf "${NAVI_HOME}/target"
rm "$SOURCE_DIR"
export SOURCE_DIR="${SOURCE_DIR:-"$(get_source_dir)"}"
rm -rf "${NAVI_HOME}/target"
rm "$SOURCE_DIR"
}

cmd="$1"
shift

case "$cmd" in
"install") install "$@" ;;
"uninstall") uninstall "$@" ;;
"install") install "$@" ;;
"uninstall") uninstall "$@" ;;
esac
10 changes: 7 additions & 3 deletions src/cheat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct SuggestionOpts {
pub header_lines: u8,
pub column: Option<u8>,
pub multi: bool,
pub delimiter: Option<String>,
}

pub type Value = (String, Option<SuggestionOpts>);
Expand All @@ -27,16 +28,18 @@ fn parse_opts(text: &str) -> SuggestionOpts {
let mut header_lines: u8 = 0;
let mut column: Option<u8> = None;
let mut multi = false;
let mut delimiter: Option<String> = None;

let mut parts = text.split(' ');

while let Some(p) = parts.next() {
match p {
"--multi" => multi = true,
"--header" | "--header-lines" => {
"--header" | "--headers" | "--header-lines" => {
header_lines = parts.next().unwrap().parse::<u8>().unwrap()
}
"--column" => column = Some(parts.next().unwrap().parse::<u8>().unwrap()),
"--delimiter" => delimiter = Some(parts.next().unwrap().to_string()),
_ => (),
}
}
Expand All @@ -45,6 +48,7 @@ fn parse_opts(text: &str) -> SuggestionOpts {
header_lines,
column,
multi,
delimiter,
}
}

Expand Down Expand Up @@ -132,8 +136,8 @@ pub fn read_all(config: &Config, stdin: &mut std::process::ChildStdin) -> HashMa

let current_exe = filesystem::exe_path_string();
let fallback = format!(
"{}/cheats:{}/../cheats:{}/../libexec/cheats",
current_exe, current_exe, current_exe
"{path}/cheats:{path}/../cheats:{path}/../libexec/cheats",
path = current_exe
);
let folders_str = config.path.as_ref().unwrap_or(&fallback);
let folders = folders_str.split(':');
Expand Down
21 changes: 18 additions & 3 deletions src/cmds/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn extract_from_selections(raw_output: &str, contains_key: bool) -> (&str, &str,
} else {
"enter"
};
let mut parts = lines.next().unwrap().split('\t');
let mut parts = lines.next().unwrap().split(display::DELIMITER);
parts.next();
parts.next();
parts.next();
Expand All @@ -68,18 +68,33 @@ fn prompt_with_suggestions(config: &Config, suggestion: &cheat::Value) -> String
..Default::default()
};

let mut column: Option<u8> = None;
let mut delimiter = r"\s\s+";

if let Some(o) = &suggestion.1 {
opts.multi = o.multi;
opts.header_lines = o.header_lines;
opts.nth = o.column;
column = o.column;
if let Some(d) = o.delimiter.as_ref() {
delimiter = d.as_str();
}
};

let (output, _) = fzf::call(opts, |stdin| {
stdin.write_all(suggestions.as_bytes()).unwrap();
None
});

output
if let Some(c) = column {
let re = regex::Regex::new(delimiter).unwrap();
let mut parts = re.split(output.as_str());
for _ in 0..(c - 1) {
parts.next().unwrap();
}
parts.next().unwrap().to_string()
} else {
output
}
}

fn prompt_without_suggestions(varname: &str) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process;
use crate::display;

fn extract_elements(argstr: &str) -> (&str, &str, &str) {
let mut parts = argstr.split('\t').skip(3);
let mut parts = argstr.split(display::DELIMITER).skip(3);
let tags = parts.next().unwrap();
let comment = parts.next().unwrap();
let snippet = parts.next().unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ static COMMENT_COLOR: color::LightCyan = color::LightCyan;
static TAG_COLOR: color::LightGreen = color::LightGreen;
static SNIPPET_COLOR: color::White = color::White;

pub static DELIMITER: char = '\t';

lazy_static! {
pub static ref WIDTHS: (usize, usize) = get_widths();
}
Expand Down Expand Up @@ -48,7 +50,7 @@ pub fn format_line(
comment_width: usize,
) -> String {
format!(
"{tag_color}{tags_short}\t{comment_color}{comment_short}\t{snippet_color}{snippet_short}\t{tags}\t{comment}\t{snippet}\t\n",
"{tag_color}{tags_short}{delimiter}{comment_color}{comment_short}{delimiter}{snippet_color}{snippet_short}{delimiter}{tags}{delimiter}{comment}{delimiter}{snippet}{delimiter}\n",
tags_short = limit_str(tags, tag_width),
comment_short = limit_str(comment, comment_width),
snippet_short = full_snippet,
Expand All @@ -57,5 +59,6 @@ pub fn format_line(
snippet_color = color::Fg(SNIPPET_COLOR),
tags = tags,
comment = comment,
delimiter = DELIMITER,
snippet = &full_snippet)
}
Loading

0 comments on commit 06eae50

Please sign in to comment.