diff --git a/Cargo.lock b/Cargo.lock index d69b2f6..5384476 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,7 +418,7 @@ dependencies = [ [[package]] name = "intelli-shell" -version = "0.2.5" +version = "0.2.6" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 6941515..3032acb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/intelli-shell.fish b/intelli-shell.fish index a7d82ed..ff6c8de 100755 --- a/intelli-shell.fish +++ b/intelli-shell.fish @@ -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 diff --git a/intelli-shell.ps1 b/intelli-shell.ps1 index 7405c22..072a0ba 100644 --- a/intelli-shell.ps1 +++ b/intelli-shell.ps1 @@ -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 @@ -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 @@ -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 diff --git a/intelli-shell.sh b/intelli-shell.sh index 7312aca..c3867e1 100755 --- a/intelli-shell.sh +++ b/intelli-shell.sh @@ -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 } @@ -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} } diff --git a/src/main.rs b/src/main.rs index 84ee839..d8de0a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)?, }, }