Skip to content

Commit

Permalink
fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
lasantosr committed May 23, 2023
1 parent 4b167dc commit 4943a41
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 49 deletions.
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.

2 changes: 1 addition & 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.5"
version = "0.2.6"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
18 changes: 6 additions & 12 deletions intelli-shell.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ function intelli-shell --description 'IntelliShell'
end

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" $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
set p_lines (fish_prompt | string split0 | wc -l)
# Swap stderr and stdout
if test (math $p_lines + 0) -gt "1"
set INTELLI_OUTPUT (intelli-shell --inline --inline-extra-line $argv 3>&1 1>&2 2>&3)
else
set INTELLI_OUTPUT (intelli-shell --inline $argv 3>&1 1>&2 2>&3)
end
# Replace line
commandline -f repaint
Expand Down
6 changes: 3 additions & 3 deletions intelli-shell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Set-PSReadLineKeyHandler -Chord $IntelliSearchChord -BriefDescription "IntelliSh
$TempFile = New-TemporaryFile
$line = $line -replace '"','""""""""""""'
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" search """"' + $line + '""""'
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command" -RedirectStandardError "NUL"
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile

Expand All @@ -33,7 +33,7 @@ Set-PSReadLineKeyHandler -Chord $IntelliBookmarkChord -BriefDescription "Intelli
if ([string]::IsNullOrWhiteSpace($line)) {
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" new'
}
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command" -RedirectStandardError "NUL"
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile

Expand All @@ -53,7 +53,7 @@ Set-PSReadLineKeyHandler -Chord $IntelliLabelChord -BriefDescription "IntelliShe
$TempFile = New-TemporaryFile
$line = $line -replace '"','""""""""""""'
$Command = 'intelli-shell.exe --file-output=""""' + $TempFile.FullName + '"""" label """"' + $line + '""""'
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command" -RedirectStandardError "NUL"
Start-Process powershell.exe -Wait -NoNewWindow -ArgumentList "-command", "$Command"
$IntelliOutput = Get-Content -Raw $TempFile
Remove-Item $TempFile

Expand Down
42 changes: 12 additions & 30 deletions intelli-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@ if [[ -n "$ZSH_VERSION" ]]; then
intelli_label_key="${INTELLI_LABEL_HOTKEY:-^l}"

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" "$@" 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 ""
p_lines=$(echo "$PS1" | wc -l)

# Swap stderr and stdout
if [ "$p_lines" -gt "1" ]; then
INTELLI_OUTPUT=$(intelli-shell --inline --inline-extra-line "$@" 3>&1 1>&2 2>&3)
else
INTELLI_OUTPUT=$(intelli-shell --inline "$@" 3>&1 1>&2 2>&3)
fi

# Rewrite line
zle reset-prompt
BUFFER="$INTELLI_OUTPUT"
BUFFER=$INTELLI_OUTPUT
zle end-of-line
}

Expand Down Expand Up @@ -59,22 +53,10 @@ elif [[ -n "$BASH" ]]; then
intelli_label_key="${INTELLI_LABEL_HOTKEY:-\C-l}"

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" "$@" 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
# Swap stderr and stdout
INTELLI_OUTPUT=$(intelli-shell --inline "$@" 3>&1 1>&2 2>&3)
# Rewrite line
READLINE_LINE="$INTELLI_OUTPUT"
READLINE_LINE=${INTELLI_OUTPUT}
READLINE_POINT=${#READLINE_LINE}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,17 @@ fn run(cli: Args) -> Result<()> {

// Print any message received
if let Some(msg) = res.message {
eprintln!("{msg}");
println!("{msg}");
if cli.inline_extra_line {
println!();
}
}

// Write out the result
match res.output {
None => (),
Some(output) => match cli.file_output {
None => execute!(io::stdout(), Print(format!("{output}\n")))?,
None => eprintln!("{output}"),
Some(path) => fs::write(path, output)?,
},
}
Expand Down

0 comments on commit 4943a41

Please sign in to comment.