Skip to content

Commit

Permalink
refactor and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lasantosr committed May 14, 2023
1 parent e4802ee commit 278e298
Show file tree
Hide file tree
Showing 27 changed files with 1,933 additions and 1,356 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ target
### Local ###
.env
.vscode/launch.json
debug.log
3 changes: 3 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{
"type": "cargo",
"command": "build",
"args": [
"--features=debug"
],
"problemMatcher": [
"$rustc"
],
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "intelli-shell"
description = "Like IntelliSense, but for shells"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand All @@ -17,6 +17,7 @@ required-features = []
[features]
default = ["tldr"]
tldr = ["dep:git2", "dep:tempfile"]
debug = []

[dependencies]
anyhow = "1"
Expand Down
38 changes: 15 additions & 23 deletions intelli-shell.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,38 @@ function intelli-shell --description 'IntelliShell'
$INTELLI_HOME/bin/intelli-shell $argv;
end

function _intelli_search
set LINE (commandline)
function _intelli_exec
# Temp file for output
set TMP_FILE (mktemp -t intelli-shell.XXXXXXXX)
set TMP_FILE_MSG (mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$TMP_FILE" search "$LINE"
intelli-shell --inline --inline-extra-line --file-output="$TMP_FILE" $argv 2> $TMP_FILE_MSG
# Capture output
set INTELLI_OUTPUT (cat "$TMP_FILE" | string collect)
set INTELLI_MESSAGE (cat "$TMP_FILE_MSG" | string collect)
rm -f $TMP_FILE
rm -f $TMP_FILE_MSG
if test -n "$INTELLI_MESSAGE"
echo $INTELLI_MESSAGE
end
# Replace line
commandline -f repaint
commandline -r "$INTELLI_OUTPUT"
end

function _intelli_search
set LINE (commandline)
_intelli_exec search "$LINE"
end

function _intelli_save
set LINE (commandline)
# Temp file for output
set TMP_FILE (mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$TMP_FILE" save "$LINE"
# Capture output
set INTELLI_OUTPUT (cat "$TMP_FILE" | string collect)
rm -f $TMP_FILE
# Replace line
commandline -f repaint
commandline -r "$INTELLI_OUTPUT"
_intelli_exec save "$LINE"
end

function _intelli_label
set LINE (commandline)
# Temp file for output
set TMP_FILE (mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$TMP_FILE" label "$LINE"
# Capture output
set INTELLI_OUTPUT (cat "$TMP_FILE" | string collect)
rm -f $TMP_FILE
# Replace line
commandline -f repaint
commandline -r "$INTELLI_OUTPUT"
_intelli_exec label "$LINE"
end

function fish_user_key_bindings
Expand Down
77 changes: 31 additions & 46 deletions intelli-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,38 @@ if [[ -n "$ZSH_VERSION" ]]; then
# zshell
# https://zsh.sourceforge.io/Guide/zshguide04.html

function _intelli_search {
function _intelli_exec {
ps1_lines=$(echo "$PS1" | wc -l)
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
tmp_file_msg=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$tmp_file" search "$BUFFER"
intelli-shell --inline --inline-extra-line --file-output="$tmp_file" "$@" 2> $tmp_file_msg
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
INTELLI_MESSAGE=$(<$tmp_file_msg)
rm -f $tmp_file
rm -f $tmp_file_msg
if [[ -n "$INTELLI_MESSAGE" ]]; then
echo "$INTELLI_MESSAGE"
[[ "$ps1_lines" -gt 1 ]] && echo ""
fi
# Rewrite line
zle reset-prompt
BUFFER="$INTELLI_OUTPUT"
zle end-of-line
}

function _intelli_search {
_intelli_exec search "$BUFFER"
}

function _intelli_save {
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$tmp_file" save "$BUFFER"
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
rm -f $tmp_file
# Rewrite line
zle reset-prompt
BUFFER="$INTELLI_OUTPUT"
zle end-of-line
_intelli_exec save "$BUFFER"
}

function _intelli_label {
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --inline-extra-line --file-output="$tmp_file" label "$BUFFER"
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
rm -f $tmp_file
# Rewrite line
zle reset-prompt
BUFFER="$INTELLI_OUTPUT"
zle end-of-line
_intelli_exec label "$BUFFER"
}

if [[ "${INTELLI_SKIP_ESC_BIND:-0}" == "0" ]]; then bindkey "\e" kill-whole-line; fi
Expand All @@ -61,43 +53,36 @@ elif [[ -n "$BASH" ]]; then
# bash
# https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-bind

function _intelli_search {
function _intelli_exec {
ps1_lines=$(echo "$PS1" | wc -l)
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
tmp_file_msg=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --file-output="$tmp_file" search "$READLINE_LINE"
intelli-shell --inline --file-output="$tmp_file" "$@" 2> $tmp_file_msg
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
INTELLI_MESSAGE=$(<$tmp_file_msg)
rm -f $tmp_file
rm -f $tmp_file_msg
if [[ -n "$INTELLI_MESSAGE" ]]; then
echo "$INTELLI_MESSAGE"
fi
# Rewrite line
READLINE_LINE="$INTELLI_OUTPUT"
READLINE_POINT=${#READLINE_LINE}
}

function _intelli_search {
_intelli_exec search "$READLINE_LINE"
}

function _intelli_save {
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --file-output="$tmp_file" save "$READLINE_LINE"
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
rm -f $tmp_file
# Rewrite line
READLINE_LINE="$INTELLI_OUTPUT"
READLINE_POINT=${#READLINE_LINE}
_intelli_exec save "$READLINE_LINE"
}

function _intelli_label {
# Temp file for output
tmp_file=$(mktemp -t intelli-shell.XXXXXXXX)
# Exec command
intelli-shell --inline --file-output="$tmp_file" label "$READLINE_LINE"
# Capture output
INTELLI_OUTPUT=$(<$tmp_file)
rm -f $tmp_file
# Rewrite line
READLINE_LINE="$INTELLI_OUTPUT"
READLINE_POINT=${#READLINE_LINE}
_intelli_exec label "$READLINE_LINE"
}

if [[ "${INTELLI_SKIP_ESC_BIND:-0}" == "0" ]]; then bind '"\e": kill-whole-line'; fi
Expand Down
Loading

0 comments on commit 278e298

Please sign in to comment.