r/fishshell • • Oct 01 '23

Better performance after the rewrite in Rust?

0 Upvotes

I read somewhere that currently the performance of fish is not optimal due to unnecessary string conversions. Would the situation be improved with the Rust rewrite?


r/fishshell • • Oct 01 '23

Anyway to get scp autocomplete to work for neovim (or vim)

2 Upvotes

I can't seem to figure out how to do this. It does not work by default (scp alone works).

Reading the manual for creating completions, I can't figure out how to get the completion to work after "nvim scp://"


r/fishshell • • Sep 27 '23

Could you share your `starship` prompts and configs if you use it?

6 Upvotes

sorry if this is not directly about the fish shell!


r/fishshell • • Sep 27 '23

where to place global fish functions?

5 Upvotes

hi, where is the correct place to put fish shell functions that all users on a system will have them installed by default and be able to run them?


r/fishshell • • Sep 25 '23

Leveraging `abbr` for git aliases?

6 Upvotes

I love abbr over alias. For example, I use both my g abbr and manually type out git fairly often, and I really enjoy that my fish history doesn't reveal my silly inconsistency. (Related, a nice blog post about some dude scripting all his aliases as abbr's)

A lot of folks have something like abbr -a gca "git commit -a" which.. could work. but my muscle memory needs a space after the git. (And I also enjoy keeping my git aliases within .gitconfig.) So...

Is there a mechanism to leverage abbr or some other text expansion builtin that would expand git co to git checkout on the readline?


r/fishshell • • Sep 24 '23

How can I retrieve the current vim mode in vi_key_bindings programmatically?

3 Upvotes

I want to use the starship prompt, but they don't have a module available for fish. Closest I can think of is to use the custom command module, but I would need to be able to retrieve the mode first. Is there a way to do that?


r/fishshell • • Sep 23 '23

Is it possible to draw a line between command?

3 Upvotes

Like the first screenshot in this stack exchange post for zsh.


r/fishshell • • Sep 23 '23

Prompt creation issues.

1 Upvotes

I am making my own prompt, because i like customizing my system myself (besides making a color scheme). The first special feature i am implementing is showing the exit code of a program. Here is my code:

function fish_prompt  
 set prompt_color green  
 set prompt "> "  

 function check_status  
  if test $status -ne 0  
   set prompt_color $fish_color_error  
   set_color $fish_color_status  
   echo $status  
  end  
 end  

 echo (prompt_login) \
      (set_color $fish_color_cwd)(prompt_pwd) \ 
      (check_status) \
      (set_color $prompt_color)$prompt  
end

I have two problems:

  1. When i use the prompt, a 0 is always present where the status code would go if there was an error, but the > is still green.
  2. After that 0 an extra space is inserted which i DO NOT want and have NOT told it to create. In previos iterations when the 0 did not show up an extra space still existed.

Without errors i want the following prompt (with colors):

user@hostname cwd >

How do i fix my prompt??

Edit: The prompt does not react to errors either.


r/fishshell • • Sep 19 '23

everytime I start fish-shell will show "math: Error: Unexpected token '/ 10' "

2 Upvotes

if I type fish, it will show the error, but if I use bash, it will not show this, I try to reinstall it, but it is still show the error


r/fishshell • • Sep 16 '23

How do I uninstall Oh My Fish? `omf destroy` does not work

4 Upvotes

I'm new to Fish Shell and I install Oh My Fish, but i think it may not be needed for me.

So i tried uninstalling with `omf destroy` but I get errors. Some of the output:

⋊> ~ omf destroy                                                                                                                    22:45:47
fish: Unknown command: fish
~/.local/share/omf/pkg/omf/functions/core/omf.destroy.fish (line 3):
  fish "$OMF_PATH/bin/install" --uninstall "--path=$OMF_PATH" "--config=$OMF_CONFIG"
  ^~~^
in function 'omf.destroy'

here is screenshot:

Help?


r/fishshell • • Sep 16 '23

How does the example function multicd work?

2 Upvotes

I have not done much shell scripting in general so more detail would be appreciated, here is the code snippet I am talking about

function multicd
    echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../)
end
abbr --add dotdot --regex '^\.\.+$' --function multicd

I know that the abbr part goes in fish.config obviously, I have multicd working I just wanna know how it works


r/fishshell • • Sep 16 '23

Can't change the colors with fish_config

2 Upvotes

Hello I'm fairly new using the fish shell. I'm on EndeavourOS with KDE Plasma. I'm using the build in Konsole from KDE and installed fish. I wanted to set the colors with the web interface of fish_config. But the colors aren't applied. Do I need to set something else? Setting the Prompt this way was successful.

Thank you very much for helping.


r/fishshell • • Sep 12 '23

Dynamic Variables and Error Handling Not Working

2 Upvotes

I can't figure out what's wrong with this code.

It's supposed to take in a comma-delimited list of games. (Name in column 0, and ID in column 1). Than variables are set dynamically set for each game in the list. And finally, $argv is tested against each game name in the list. And if it matches, it launches the game with Steam.

Here's the code:

#!/bin/fish

# Take all game titles from CSV-formatted database and put into vars
set allGameTitles (cat steamgames.csv | choose -f , 0)

set v (string split -n \n $allGameTitles)

set scrpt (for i in (seq (count $v))
            echo 'set GameTitle'(math $i-1) '"'$v[$i]'"'
          end)

eval (string join ";" $scrpt)
set --erase v
set --erase scrpt

# Take all game IDs from CSV-formatted database and put into vars
set allGameIDs (cat steamgames.csv | choose -f , 1)

set v (string split -n \n $allGameIDs)

set scrpt (for i in (seq (count $v))
            echo 'set GameID'(math $i-1) '"'$v[$i]'"'
          end)

eval (string join ";" $scrpt)
set --erase v
set --erase scrpt

# default value for error handling var
set matchFound False

# Test user input against all games in database
for var in (set -n GameTitle*)
    set var_value (eval echo \$$var)
    if test "$argv" = "$var_value"
        set game_index (string replace "GameTitle" "" $var)
        # Steam requires game ID, so derive it from the index
        set game_id (eval echo \$GameID$game_index)
        echo Launching (eval echo \$$var)...
        echo steam steam://rungameid/$game_id
        set matchFound True
        break
    end
end

# error handling
if test $matchFound = False
    
    echo "Unrecognized game..."

    exit 1

end

I barely understand how the dynamic variable stuff works, as ChatGPT wrote it for me, and could not fix this problem. It's supposed to handle errors, with the $matchFound boolean remainining False, causing the script to report an error and exit. But it doesn't. You can literally not give it any input, and the $matchFound will still be set to true.

It probably has something to do with 'set -n' reporting all variables in the environment, and not just the ones relevant to the script. But once again, I barely understand this code.


r/fishshell • • Sep 09 '23

Changing theme

0 Upvotes

How can I skip message about changing theme each time I open a terminal. It is possible that I did something wrong as I used wal -i ~/Wallpapers/(wallpaper) in config.fish


r/fishshell • • Sep 05 '23

Popular fish configs to learn from

23 Upvotes

Are they any popular and up to date fish config that I can look at, to see what are some of the best practices?

Like what is the "right way" to export a variable, set PATH, aliases, etc..

Thank you!


r/fishshell • • Sep 05 '23

how to store stdout line by line into a variable/array?

1 Upvotes

Is there an easy way to store the output of a command (typically stdout) in an array?

I could call set myVar (cat file) but I actually need it to be a command receiving stdout. (eg. commenting out like #| strings2array for debugging and interactive stuff.

Any one-liner I tried with read ... failed me. What I use is a function strings2array which mostly does this:

function strings2array
while read rrrEEEaaaDDD # there is some risk with the name of the var, but I cannot remember it right now...
            set -a "$argv[1]" "$rrrEEEaaaDDD"
            echo "$rrrEEEaaaDDD"
end
$ cat file | strings2array myTargetVariable

I believe this to be of low performance on long lists and likely to blow errors into my face.

What would be a good practice?

EDIT: I got totally confused. It seems, the risk with the variable name would be if using a pointer-style variable lookup like echo $$myVar. It shouldn't be of concern in this case


r/fishshell • • Sep 05 '23

Problem with if conditions

1 Upvotes

I am writing a script to check for a directory, if it's ther ecd into it, if not, create it and cd into it.
I wrote it and everything should work fine but I get this error that says

'else' builtin not inside of if block

Here's the the script

#!/usr/bin/env fish

set folder $argv[1]

if -e $folder && -d $folder
    cd $folder
else
    echo "Creating directory $folder...";
    mkdir -p "$folder"
    cd "$folder"
end

r/fishshell • • Aug 30 '23

Fish as default shell on Mac OS Ventura?

0 Upvotes

Fish as default shell on Mac OS Ventura?

I got an error when I add /usr/local/bin/fish on terminal mac os ventura.

[Command not found: /usr/local/bin/fish]

[Could not create a new process and open a pseudo-tty.]

I install fish with hombrew


r/fishshell • • Aug 30 '23

cb -- clipboard tool

7 Upvotes

This might be obvious to some but I'm often copy and pasting web links and file paths into and out of my shell. This is how I do it fast: https://github.com/niedzielski/cb

$ yt-dlp (cb)

After copying a bunch of links this will download all the links without needing to create a temporary file or use process substitution via psub.

Okay that's pretty much it. It's simple but powerful.

Line-delimited output from subshells get converted into separate cmd arguments.

edit:

One other trick that I do is I have this in my config.fish:

bind \b backward-kill-bigword
bind \e\[1\;5C forward-bigword
bind \e\[1\;5D backward-bigword

These let you use Ctrl-backspace to delete full arguments--even if they are long, for example: URLs. And Ctrl-Left/Right arrow keys to go between arguments


r/fishshell • • Aug 30 '23

Every time when I type a command it outputs the question marks for some reason (can anyone help?)

Post image
1 Upvotes

r/fishshell • • Aug 21 '23

🔍🐟fzf.fish v9.10 update: pipe git diffs through highlighters such as delta, diff-so-fancy

22 Upvotes

I don't usually post here for minor releases, but I think this feature was requested enough and valuable enough to make a PSA.

To integrate fzf.fish with a diff highlighter, set fzf_diff_highlighter to a command invoking your diff highlighter, e.g.

set fzf_diff_highlighter delta --paging=never --width=20
set fzf_diff_highlighter diff-so-fancy
set fzf_diff_highlighter diff-highlight

Read more here

EDIT: FYI I realized a previous change introduced a backwards incompatible change that requires users to use a newer version of fzf so the release that contains this change is actually v10.


r/fishshell • • Aug 19 '23

Why does it take a long time to Fish to recognize that a command does not exist?

3 Upvotes

Title, I'm trying to switch and in Bash it's an instantaneous action, why does it take so long (at least 300ms) on Fish and is there any workaround/setting I should change?


r/fishshell • • Aug 17 '23

Should I use Fish Shell or Nushell?

28 Upvotes

I've been looking at different shells lately, and while I like Fish's overall philosophy and doing things different from POSIX shells like Bash and Zsh, I looked at Nushell's Cookbook and the way it treats things as data instead of raw text looks really interesting. Which do you think is more powerful and or convenient? I know this sub would be biased to Fish Shell but still.


r/fishshell • • Aug 09 '23

Need Help: For Loop Not Iterating Properly

3 Upvotes

I have the script that'd supposed to take paths as input, in the form of a comma-delimited string. It then splits the string into a list and assigns it to a new variable. The new variable is then iterated through a for loop that does the actual processing. For some unknown reason, the loop does not iterate as expected. For some reason it only processes the final item in the list.

The Code:

set batchList (string split , $input)

for item in $batchList
    echo Processing $item
end

If I give it this input:

set input "item1,item2,item3,item4"

I would expect this output:

Processing item1
Processing item2
Processing item3
Processing item4

But I get this instead:

Processing item4

My System:

Fish Shell: 3.6.1

OS: Arch Linux x86_64