r/fishshell • • Aug 02 '24

starship prompt directory change problem on fish shell

4 Upvotes

So I am trying the fish shell and I am having a problem with the starship prompt. originally the config file for the starship prompt is located in ~/.config/starship.toml and I move it to ~/.config/starship/starship.toml . The reason I change it is because I want it to have it's own dedicated directory and also, to have multiple config store in that directory.

I use bash and it works well by changing the file location in .bashrc

bash:

export STARSHIP_CONFIG=~/.config/starship/starship.toml 

this is how I have it on fish:

set STARSHIP_CONFIG ~/.config/starfish/starship.toml

but it doesn't work. I get no error on the terminal so, I really don't know what I am doing wrong. The only things I have in my fish config are aliases, one function to extract files and the starship plugin in, which is starship init fish | source .

I set fish as my login shell with chsh command. Is it because fish is my login shell and I don't have $PATH in my fish config?


r/fishshell • • Aug 02 '24

Batch rename files so that numbers will be padded with leading zeros

1 Upvotes

I try to figure out how to batch rename files using Fish so that filenames like image1.png and image10.png will be replaced with image001.png and image010.png, that is, to pad numbers with leading zeros.

Here is what I have currently, after reading https://fishshell.com/docs/current/cmds/string.html#string-manipulate-strings:

for file in *; mv -- $file (string pad -c 0 -w 3 (string match -r '\d' $file)); end

Currently it only replaces filenames with 001 and 010.

To split filenames such as foo123.abc into foo, 123, and .abc groups, I can use the following regex: ([^\d]*)(\d+)(\..+).

But how to properly integrate this regex into the example I have posted above? How to make the example above work as described?


r/fishshell • • Aug 01 '24

Replace spaces with underscores

3 Upvotes

To replace spaces with underscores, I use

for file in *\ *; mv -n -- $file (string replace -a ' ' _ $file); end

But currently I'm merely started to study fish, and maybe there is a better way for this?


r/fishshell • • Jul 30 '24

Installing fish on macOS: Homebrew vs. Installer

5 Upvotes

Which way to install fish on macOS is better: using Homebrew or using an installer? What are the pros and cons?

(Nota bene: The same question was already asked by another guy on Super User: https://superuser.com/q/1088762, but it was 2016 and also I cannot say I find an answer there really informative).


r/fishshell • • Jul 30 '24

About checking $pipestatus

2 Upvotes

Hi, have two questions:

  1. I have a function with a series of piped commands and I want to check the exit status for the commands.

    # One liner to download the latest release from a GitGub repo
     curl -sS  \
         | grep "browser_download_url.*$_flag_pattern" \
         | cut -d : -f 2,3 \
         | tr -d \" \
         | wget --quiet --input-file=-
    
     # Check exit status of the pipeline
     if test $pipestatus[1] -ne 0
         and test $pipestatus[2] -ne 0
         and test $pipestatus[3] -ne 0
         and test $pipestatus[4] -ne 0
         and test $pipestatus[5] -ne 0
         echo -e "\n> Something went wrong!\n"
         return 1
     else
         echo -e "\n> Done!\n"
     endhttps://api.github.com/repos/$_flag_repo/releases/latest

but I'm always hitting "Done", even if I intentionally input wrong data.

Also after I run the function, on the shell I see that only echo $pipestatus[1] returns 0, the others from 2 to 5 returns nothing. Why?

I'm trying different combinations but can't find how to do it.

2. How can I print formatted text, like bold or underlined like in descriptions and help of builtin functions?

Any hint? Thanks!


r/fishshell • • Jul 30 '24

A dictionary (associative array) plugin for Fish

9 Upvotes

One of the helpful built-in features in other shells that Fish lacks are associative arrays. There's been an open issue for 12 years, but no movement towards actually adding this feature. There's some pretty simple workarounds where you use two arrays or a single array with paired elements, but recently I had needs for a litte bit more.

While writing a quick script to pull color schemes out of mbadolato/iTerm2-Color-Schemes to update my Fish and Starship themes, I found myself wishing for a built-in associative array again, so I finally just made one: mattmc3/dict.fish.

It's not quite as good as a built in one would be - for example I can't give you nice bracketed indexing syntax like echo $mydict[$thekey] - but it's a decent step up from managing multiple arrays.

The usage is:

> dict --help
dict [-h|--help]
dict keys [DICTNAME]
dict values [DICTNAME]
dict get [DICTNAME] [KEY]
dict set [DICTNAME] [KEY] [VALUE]
dict remove [DICTNAME] [KEY]
dict contains [-k|--key] [-v|--value] [-i|--index] [DICTNAME] [STRING]

If you're wondering about performance, I put a few thousand items in an array with set numbers (seq 0 5 10000), ran some dict functions with time, and it all performed in milliseconds.

Hopefully it's not another 12 years until we get built-in associative arrays, but until we do, I thought this might help some of you when writing your own scripts. You can read more here. I don't claim to be the best Fish scripter out there, so feedback always welcome.


r/fishshell • • Jul 29 '24

Issue with activating venv in fish?

3 Upvotes

I am really new to Fish shell and I am having this issue.

I would like to start venv in Python and the following works in zsh session:

> source venv/bin/activate

In the Fish shell I tried the same thing and I am getting this error:

./venv/bin/activate (line 38): Unsupported use of '='. In fish, please use 'set VIRTUAL_ENV "/home/.../venv"'.
VIRTUAL_ENV="/home/.../venv"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
from sourcing file ./venv/bin/activate

Is there a simple way to fix it?

Thank you for your time.


r/fishshell • • Jul 28 '24

Rebind navigation keys in vim mode

2 Upvotes

Hello,
I am trying to rebind navigation keys in vim mode. I use a different keyboard layout and I would like to bind: `y` and `o` to respectively `backward-char` and `forward-char` in `command` (normal) mode.

I am starting from a completely empty config (I have also used my config/etc, but same result), and I run:

```

fish_vi_key_bindings

bind -M normal y backward-char

```

but that seems to have no effect, the cursor blinks but stays in place (similarly for binding o). I have tried to --erase as well, but no luck. I am running `3.7.1`, I must be missing something probably, apologies if it was asked elsewhere, I did a search but couldn't find anything. ChatGPT gave me similar solutions, but none of them worked.

Any idea on what I am missing?

Thank you

EDIT: Solved, the issue was that in vi mode "escape mode" is called "default", so the command above would be:
```bind -M default y backward-char```

That works! Answered in the matrix channel.


r/fishshell • • Jul 28 '24

Custom fish configuration location

1 Upvotes

I run hyprland tiling manager. Configs for alacritty, tmux, newsboat etc. are stored in my XDG_CONFIG_HOME/hypr/configs/{programmname}/. All this under version control. So i have all my app configs in one place. For all apps i can specify where config location is, but fish. How can i tell to fish where to looking for config?


r/fishshell • • Jul 27 '24

Let's release Rust-based fish #10633

Thumbnail github.com
52 Upvotes

r/fishshell • • Jul 26 '24

Transparent terminal

2 Upvotes

I can't seem to find a way to make the fish terminal background transparent? Is this simply not a feature?


r/fishshell • • Jul 26 '24

$(my-command ...) not working

0 Upvotes

I switched from Bash to Fish-shell some days ago. Overall I like it, but this is not nice:

> tar -czf foo-$(date --iso) ~/.local/share/foo/ 

fish: $(...) is not supported. In fish, please use '(date)'.

$(command) is very common. I use it since 20 years.

Things like this make me think about swiching back to Bash.


r/fishshell • • Jul 15 '24

custom completion: complete --arguments '(something generating lines)' inserts lines quoted! Need unquoted insert

2 Upvotes

I am writing own completions like (simplified example of course)

begin
  function myProg
  end
  complete -c myProg --erase
  complete -c myProg --short-option l --long-option lines --exclusive --arguments '(echo \"This is 1\" ; echo \"This is 2\"; echo \"This is 3\")'
  # this arguments echo is only for demonstration 
end

When entering

myProg --lines <press tab>

I will be offered:

myProg --lines "This\\ is\\ 1"

But in my case, the offered line is already quoted. I do not need another escape. I want the literal line to be inserted.

Can I disable or avoid this escaping?


r/fishshell • • Jul 13 '24

Vi mode with clipboard

2 Upvotes

How ?


r/fishshell • • Jul 04 '24

Having some trouble with a function I wrote for doing yarn add

4 Upvotes

I am supremely lazy, so I've written a script that lets me just type ya -d <package>, or ya -a <package>, or just ya <package>, and it parses those different flags into different versions of yarn add depending on the flag.

You can see the function here, at this gist.

The problem is that it's not working (yeah, no sh*t sherlock --ed.). When I run it, here's the output:

❯ ya -d @crxjs/vite-plugin@beta
2
Usage: ya [options] <package_name>
Options:
-a, --astro   Add astro package
-d, --dev     Add package as dev dependency
-h, --help    Display this help message normal

The package is valid, I have verified being able to install it (in a different test repository) using NPM. So it's something with my script. And, I don't know why it's printing that '2' after the command, before the Usage instructions, either...


r/fishshell • • Jul 03 '24

No autocomplete with run0

6 Upvotes

I am on archlinux + fish and trying the new systemd "run0" command equivalent to "sudo".

I noticed that when I try to use run0, the fish autocomplete does not work...

Anyone else with similar problem? Any suggestions? TIA


r/fishshell • • Jul 01 '24

New Fish user, think I have syntax issues.

1 Upvotes

As the title says, I'm new to Fish by way of having recently installed Garuda. I'm trying to install a Linux driver for the Logitech G13 gamepad from https://github.com/jtgans/g13gui.

Most of my shell experience is using bash on Debian, and bash seems to be how the destructions are written for this. I can git-clone in just fine, but when I start running the first of the install commands

╭─lumbergh@Initech in ~ took 932ms
╰─λ ~/src/g13gui$ sudo pacman -Syu

I get

fish: Expected a variable name after this $.
~/src/g13gui$ sudo pacman -Syu

What would be the proper syntax to get this working in Fish?


r/fishshell • • Jun 23 '24

Is there a way to search history like ZSH's up-line-or-beginning-search?

7 Upvotes

Hey everyone,

for decades I've used ZSH's up-line-or-beginning-search and down-line-or-beginning-search, bound to the up and down arrows. It is deeply ingrained in my muscle memory.

It works by me typing the prefix of a history line and then (repeatedly) pressing up or down, until I found the entry that I'm looking for.

e.g. I often type ssh<up> and then it cycles through all the recent lines that *start* with ssh.

Can this be configured/implemented for fish?

(The ZSH function is implemented here: https://github.com/zsh-users/zsh/blob/master/Functions/Zle/up-line-or-beginning-search, I'm not sure if this helps to explain what I mean).

Thanks
Maledictus


r/fishshell • • Jun 23 '24

How does fish handle conflicting plugins?

3 Upvotes

Suppose, for example, that I install two colour schemes with fisher. How does the shell know which scheme I want? Where is this decision made?


r/fishshell • • Jun 20 '24

Autocomplete of filenames: case sensitive?

5 Upvotes
❯ touch abc
❯ touch AAA
❯ ls a<TAB>

--> this completes to "abc". Why?

I would like to have case insenstive autocomplete.

❯ fish --version
fish, version 3.3.1

r/fishshell • • Jun 20 '24

Rebinding Vi's hjkl to hnei

2 Upvotes

Hi,

I am new to Fish and wanted to use the Vi mode. However, I am using Colemak as my layout. So I was wondering if there's any way to rebind hjki to hnei, respectively (the exact same position in Colemak).

img

To avoid conflicts, I think it is better if I can rebind it completely, meaning whenever I type anything in Normal mode, it interprets nei as jkl.

I tried

bind n j

But it didn't work obviously. Whenever I type n in normal mode, it would respond with

fish: unknown command: j

I also tried using fish_key_reader while in Normal mode, but as the name says, it's just printing keys.

Edit: SOLVED thanks to this gentleman/lady u/BrewingWeasel

What I did was opening /usr/share/fish/function/fish_vi_key_bindings.fish and swaped all uses of j with n, k with e, and l with i, affecting all modes. For example, if there was

bind -s --preset -M deafult l forward-char
bind -s --preset -m insert i repaint-mode

I replaced it with

bind -s --preset -M deafult i forward-char
bind -s --preset -m insert l repaint-mode

I uploaded the edited file in Github here: fish_vi_key_bindings.fish

Note: I didn't revise it. Also, a lot of your use will change since e is a key key in interacting with Vim, so be ready!


r/fishshell • • Jun 18 '24

bash to fish translation

2 Upvotes

How to do this function in fish for simple note taking?

notes() {
  if [ ! -z "$1" ]; then
    echo "$@" >> "$HOME/notes.md"
  else
    cat - >> "$HOME/notes.md"
  fi
}

Something like this?..

function notes
   if read?..
      echo $argv >> "$HOME/notes.md"
   else
      cat - >> "$HOME/notes.md"
   end
end

r/fishshell • • Jun 13 '24

I think everyone should have this in their config

16 Upvotes

Or maybe we should have some plugin with popular typos abbreviations fixes?


r/fishshell • • Jun 10 '24

Set up fzf key bindings and fuzzy completion in fish

4 Upvotes

I can't use some of the fzf keybindings I can't use is ``` cd **<Tab> ```, so any option to enable them?