mirror of
https://github.com/junegunn/fzf.git
synced 2026-08-03 14:38:34 +08:00
shell: nushell integration scripts (#4630)
Co-authored-by: imsys <911254+imsys@users.noreply.github.com> Co-authored-by: Grzegorz Zalewski (Greg) <12560152+zalewskigrzegorz@users.noreply.github.com> Co-authored-by: René Jochum <rene@jochum.dev> Co-authored-by: Junegunn Choi <junegunn.c@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
imsys
Grzegorz Zalewski
René Jochum
Junegunn Choi
Copilot Autofix powered by AI
parent
ccedd064ca
commit
290b18d9fe
+66
-8
@@ -78,6 +78,38 @@ class Shell
|
||||
"rm -f ~/.local/share/fish/fzf_test_history; XDG_CONFIG_HOME=#{confdir} fish"
|
||||
end
|
||||
end
|
||||
|
||||
def nushell
|
||||
@nushell ||=
|
||||
begin
|
||||
xdg_home = '/tmp/fzf-nushell-xdg'
|
||||
config_dir = "#{xdg_home}/nushell"
|
||||
FileUtils.rm_rf(xdg_home)
|
||||
FileUtils.mkdir_p(config_dir)
|
||||
|
||||
# Write env.nu to set up PATH and unset FZF variables
|
||||
File.open("#{config_dir}/env.nu", 'w') do |f|
|
||||
f.puts "$env.PATH = ($env.PATH | split row (char esep) | prepend '#{BASE}/bin')"
|
||||
UNSETS.each do |var|
|
||||
f.puts "hide-env -i #{var}"
|
||||
end
|
||||
f.puts "$env.FZF_DEFAULT_OPTS = \"--no-scrollbar --pointer '>' --marker '>'\""
|
||||
f.puts '$env.config = ($env.config | upsert history { file_format: "plaintext", max_size: 100 })'
|
||||
end
|
||||
|
||||
# Write config.nu with minimal prompt
|
||||
File.open("#{config_dir}/config.nu", 'w') do |f|
|
||||
f.puts '$env.PROMPT_COMMAND = {|| "" }'
|
||||
f.puts '$env.PROMPT_INDICATOR = ""'
|
||||
f.puts '$env.PROMPT_COMMAND_RIGHT = {|| "" }'
|
||||
f.puts '$env.config = ($env.config | upsert show_banner false)'
|
||||
f.puts "source #{BASE}/shell/key-bindings.nu"
|
||||
f.puts "source #{BASE}/shell/completion.nu"
|
||||
end
|
||||
|
||||
"unset #{UNSETS.join(' ')}; env XDG_CONFIG_HOME=#{xdg_home} XDG_DATA_HOME=#{xdg_home}/../fzf-nushell-data nu --config #{config_dir}/config.nu --env-config #{config_dir}/env.nu"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,12 +117,30 @@ class Tmux
|
||||
attr_reader :win
|
||||
|
||||
def initialize(shell = :bash)
|
||||
@shell = shell
|
||||
@win = go(%W[new-window -d -P -F #I #{Shell.send(shell)}]).first
|
||||
go(%W[set-window-option -t #{@win} pane-base-index 0])
|
||||
return unless shell == :fish
|
||||
|
||||
send_keys 'function fish_prompt; end; clear', :Enter
|
||||
self.until(&:empty?)
|
||||
if shell == :fish
|
||||
send_keys 'function fish_prompt; end; clear', :Enter
|
||||
self.until(&:empty?)
|
||||
elsif shell == :nushell
|
||||
# Clear history from previous tests to avoid contamination
|
||||
FileUtils.rm_f('/tmp/fzf-nushell-xdg/nushell/history.txt')
|
||||
# Wait for nushell to be ready by polling with a marker command.
|
||||
# We use 'print "fzf-ready"' and check for a line that is exactly
|
||||
# 'fzf-ready' (not the command echo which includes 'print').
|
||||
retries = 0
|
||||
begin
|
||||
send_keys 'print "fzf-ready"', :Enter
|
||||
self.until { |lines| lines.any? { |l| l.strip == 'fzf-ready' } }
|
||||
rescue Minitest::Assertion
|
||||
retries += 1
|
||||
raise if retries > 5
|
||||
retry
|
||||
end
|
||||
send_keys 'clear', :Enter
|
||||
self.until(&:empty?)
|
||||
end
|
||||
end
|
||||
|
||||
def kill
|
||||
@@ -242,11 +292,19 @@ class Tmux
|
||||
def prepare
|
||||
tries = 0
|
||||
begin
|
||||
self.until(true) do |lines|
|
||||
if @shell == :nushell
|
||||
message = "Prepare[#{tries}]"
|
||||
send_keys ' ', 'C-u', :Enter, message, :Left, :Right
|
||||
sleep(0.15)
|
||||
lines[-1] == message
|
||||
send_keys 'C-u', 'C-l'
|
||||
sleep 0.2
|
||||
send_keys ' ', 'C-u', :Enter, message
|
||||
self.until { |lines| lines[-1] == message }
|
||||
else
|
||||
self.until(true) do |lines|
|
||||
message = "Prepare[#{tries}]"
|
||||
send_keys ' ', 'C-u', :Enter, message, :Left, :Right
|
||||
sleep(0.15)
|
||||
lines[-1] == message
|
||||
end
|
||||
end
|
||||
rescue Minitest::Assertion
|
||||
(tries += 1) < 5 ? retry : raise
|
||||
|
||||
Reference in New Issue
Block a user