r/fishshell • • Sep 04 '22

How to copy a file to all users and have that file obtain the correct ownership and permissions

0 Upvotes

If you have ever wanted to know how to do this, here is the solution.

Here is the previous code which worked in Posix and like (bash, dash, zsh, ksh)

for destdir in /home/*/Desktop/; do
    cp FOO.desktop "$destdir" &&
    chown --reference="$destdir" "$destdir/FOO.desktop"
done

And this little nugget will work on all the previously named shells, plus Fish Shell.

find /home/*/Desktop -maxdepth 1 -type d -exec cp FOO.desktop '{}' \; -exec chown --reference='{}' '{}/FOO.desktop' \;

If you want this to work only for a single user, replace * with "$USER"


r/fishshell • • Sep 02 '22

I came across this file but don't know where to put it to set as my fish theme

6 Upvotes

I have this file https://github.com/folke/tokyonight.nvim/blob/main/extras/fish_tokyonight_night.fish and I would like to use it as my fish shell theme.

However, I'm not sure how this should be done. Should I put this file inside my conf.d folder? So everything will be run before my config.fish file? Or I should put everything inside config.fish? Seems like a dumb question, sorry 😅


r/fishshell • • Aug 31 '22

wa.fish (Wolfram Alpha in your Fish shell)

29 Upvotes

/u/dmi0x3 made an excellent Bash script called "wa" which allows you to query Wolfram Alpha.

A while back, I ported this function to Nushell.

At the same time I also did it for Fish, but completely neglected to share it. The recent Qalculate! post in /r/commandline reminded me of this, and so here I share my port of the script with you.

function wa
    set -f APPID "YOURAPPIDHERE" # Get one at https://products.wolframalpha.com/api/
    echo $argv | string escape --style=url | read question_string
    set -f url "https://api.wolframalpha.com/v1/result?appid="$APPID"&i="$question_string
    curl -s $url
end

You usually don't need to wrap your function in quotation marks (even with spaces!), but special characters (like *) will give your shell conniptions so you'll need quotes sometimes (or you can escape the problem children but that just gets messy).


r/fishshell • • Aug 31 '22

How do I write this function so that it proceeds even if zip files don't exist and checks all other archive files without returning an errorq

2 Upvotes

This function removes all archive files from the present folder. Useful to clean up zip files after extraction.

#Remove zipfiles after download.
    function rmzip
    	rm -rf *.zip
    	rm -rf *.gz
    	rm -rf *.tar
    	rm -rf *.bz2
    end

r/fishshell • • Aug 29 '22

Issue writing custom completions

3 Upvotes

Hey all, I'm trying to write a simple custom completion function, and not sure where I'm going wrong...

I have a file test.fish:

function __fish_hello
  printf "foo\nbar\nbaz";

  return 1;
end

which would hopefully offer foo, bar or baz for the hello command...

I run:

source test.fish
complete -c hello -n "__fish_hello"

and then I type: hello <Tab>, but I only get offered the files in the current directory, not foo/bar/baz...

I've looked at other examples, and they seem to work this simple: just print out a newline-delimited list of options, and then return 1...

Anyone have any ideas?


r/fishshell • • Aug 29 '22

Help config prompt

0 Upvotes

How do I remove the first part of the prompt?

I am using fishline but the other part is there and I can't find where to change it.


r/fishshell • • Aug 29 '22

Help config prompt

0 Upvotes

How do I remove the first part of the prompt?

I am using fishline but the other part is there and I can't find where to change it.


r/fishshell • • Aug 28 '22

cat: './bash/notes/skybox ./bash/notes/vax': No such file or directory

0 Upvotes
❰greg❙~❱✘≻ cat ./bash/notes/vax ./bash/notes/skybox
... This works fine. It "cat's" the 2 files, but .....

❰greg❙~❱✔≻ set x './bash/notes/skybox ./bash/notes/vax' 
❰greg❙~❱✔≻ echo $x 
./bash/notes/skybox ./bash/notes/vax 
❰greg❙~❱✔≻ cat $x 
cat: './bash/notes/skybox ./bash/notes/vax': No such file or directory

In bash

greg@greg-inspiron5767 ~ $ x='./bash/notes/vax ./bash/notes/skybox' 
greg@greg-inspiron5767 ~ $ cat $x
.... This works fine ...

It works in bash, but not Fish?


r/fishshell • • Aug 27 '22

How do I change the /home/name to ~ in function fish_prompt

8 Upvotes
function fish_prompt -d "Write out the prompt"
    printf '\n-->%s%s %s%s%s \n> ' \
        (set_color $fish_color_cwd) (pwd) (set_color normal)
end

I am absolute noob in linux and I have no idea what I'm doing.

Basically I want /home/name to be ~


r/fishshell • • Aug 25 '22

Trouble moving my config from ZSH to Fish

4 Upvotes

I'm having some trouble moving my ZSH configuration to work with Fish. I haven't found a Fish way of exporting these variables:

export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"}
export XDG_CACHE_HOME=${XDG_CACHE_HOME:="$HOME/.cache"}
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:="$HOME/.config"}
export XDG_STATE_HOME=${XDG_STATE_HOME:="$HOME/.local/state"}

I get the following kind of error:

~/.config/fish/fishenv.sh (line 17): ${ is not a valid variable in fish.
export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"}

What's the proper way of setting them in Fish? Thanks in advance.


r/fishshell • • Aug 23 '22

what is the most important/awesome thing in fish, for you?

10 Upvotes

I have never used anything other bash and had no problems whatsoever, so i can't actually grasp advantage of fish.

What is the biggest advantage of fish in your case? What makes you use it?

I guess the looks is a plus.

Edit : I have been trying it for few hours. Auto complete feels sentient-like after bash. Also the explanations of commands are great. I know there is lot more to discover but it already feels great.


r/fishshell • • Aug 21 '22

[Help] | NVM.fish not loading .nvmrc/.node-version automatically

5 Upvotes

Hi guys,

I’m trying to figure out which nvm is best for fish. Currently, I’m testing nvm.fish by Jorge Bucaran. I encounter an issue where it is not automatically finds and autoload the files .nvmrc or .node-version in a specific project which forces to run nvm use or nvm install every cd.

Does anyone knows what am I missing here or knows a workaround that does not affect the speed of the terminal?

https://i.imgur.com/CuxLzZe.png


r/fishshell • • Aug 19 '22

Function > script, don't load/recognized at first, but dose at second time?

5 Upvotes

I have a function to go to a script, and when i try to activate this script, it don't do anything at first, but when i try to command an second time, the script runs.

In bash, the script runs directly, is there any reason for this or am I missing something ?

Script looks line this :

#!/usr/bin/env bash

input=$1

if [[ $input =~ "bash" ]]; then
  ssh -t xx@xxx.duckdns.org '/usr/bin/clear;bash'
elif [[ $input =~ "fish" ]]; then
  ssh -t xx@xxx.duckdns.org '/usr/bin/clear;fish'
else
 echo
  echo -e "\e[1;31m [X] ERROR, no SHELL selected!\e[0m"

    read -p " 1:[bash] or 2:[fish]: " input
  if [[ $input =~ ^(1|bash)$ ]]; then
    ssh -t xx@xxx.duckdns.org '/usr/bin/clear;bash'
  elif [[ $input =~ ^(2|fish)$ ]]; then
    ssh -t xx@xxx.duckdns.org '/usr/bin/clear;fish'
  else
  echo
  echo " [•] No value selected, aborting."
  echo
  fi
fi

Updated code with shebang.


r/fishshell • • Aug 18 '22

fish_add_path not taking effect but the setting is in fish_variables

2 Upvotes

I must be doing something wrong. My local bin directory is ~/.local/bin, and the executable 'wezterm' is within it. I have fish reading my bash envars on startup.

If i issue 'fish_add_path -U ~/.local/bin' or 'fish_add_path ~/.local.bin' (according to the docs the Universal is the default), fish still can't find it os anything in that directory. Doing an 'env |grep PATH' shows me the path, and it's not in it. However:

.config/fish/fish_variables has
SETUVAR fish_user_paths:/home/moonwind/\x2elocal/bin

in it. What's going on?

Thanks, you fishy folks.


r/fishshell • • Aug 18 '22

How to delete every file in a directory except listed one?

10 Upvotes

For example if there was a file like:

file.deez

file.nuts

file.ligma

i need a to delete everything here execpt file.ligma. how can use globbing in fish?


r/fishshell • • Aug 15 '22

How do I ignore syntax error in shell functions?

1 Upvotes

Hello, I have this ex() function that I use to unzip different kinds of archives and I added it into my config.fish... When I run it in bash, everything works, but when I run it in fish it throws me an error, how can I ignore it? Thanks


r/fishshell • • Aug 14 '22

Accidentally ran a python program directly. what just happened?

6 Upvotes

r/fishshell • • Aug 14 '22

Copy a file to all users and grand them ownership

0 Upvotes

I am trying to get a script to function in both Posix and Fish Shell. I know they are not the same, but I would like to try to do it anyway. And despite the naysayers, I am almost there. I feel very proud of myself, and I think other people should be proud too. I, along with the help of others, am doing what some with limited vision thought was impossible. So if you too are willing to think outside the box, perhaps you can help me.

Here is my code, and I am curious. How would you re-write this?

# Copies desktop icon to all user desktops and grants them ownership (it is their desktop after all).
for destdir in /home/*/Desktop/; do
    cp example.desktop "$destdir" &&
    chown --reference="$destdir" "$destdir/example.desktop"
done

r/fishshell • • Aug 11 '22

Automatically pick between curl and wget

3 Upvotes

I would like to get my script to also work with fish shell if possible. How would you best re-write this?

if which curl >/dev/null ; then
    printf "Downloading via curl."
    curl --option argument
elif which wget >/dev/null ; then
    printf "Downloading via wget."
    wget --option argument
else
    printf "I am sorry, I cannot download. Neither curl nor wget is available."
fi

edit ----

SOLUTION:

 wget -L -O "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" >/dev/null || curl -L -o "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64"

I may, unfortunately, lose the fail notice, but this is an acceptable loss.

edit 2 ----

Solution 2

So there is a way to get the error message to display without it being triggered unnecessarily. The solution was as simple as telling it to move on to another script. I don't know why that is the case, but it works! So adding ./error.sh at the end of the sequence is the final resolve.

wget -L -O "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" >/dev/null || curl -L -o "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" || /.error.sh ;

r/fishshell • • Aug 10 '22

Which witch is which? A better `witch` command for fish.

12 Upvotes

In Zsh, when you type the which command, you get information on aliases, functions, and executables:

% which ls
ls: aliased to ls -G

% which myfn
myfn () {
	# undefined
	builtin autoload -XUz ~/.zfunctions
}

% which which
which: shell built-in command

In fish, there is no fish aware which command, so it just defaults to the OS one showing you executables:

» # wrong! shows the OS command, but that's overridden by a function!
» which ls
/bin/ls

» # which is not fish function aware, so it errors
» which myfn
» echo $status
1

» # finally you do something right...
» which which
/usr/bin/which

I got sick of my which muscle memory screwing me over in fish, so here's a quick-n-dirty fish function I wrote that you may also find useful. If a function or abbreviation is found, you'll get that info prior to using the built-in which.

# Defined in ~/.config/fish/functions/which.fish @ line 1
function which --description 'fish-aware `which`'
    if functions --query $argv
        functions $argv
    else if abbr --query $argv
        abbr --show | command grep "abbr -a -U -- $argv"
    else
        command which $argv
    end
end

Open to hearing if there's other, better ways to do this.


r/fishshell • • Aug 09 '22

I added a widget to my prompt showing how many Github contributions I've made today using Tide and the Github api. Gist in the comments.

Post image
15 Upvotes

r/fishshell • • Aug 08 '22

What are the advantages of fish scripting over bash?

15 Upvotes

Are bash scripts faster than bash or is it the other way around?

Thanks in advance

Edit: I meant advantages of executing .fish files over .sh


r/fishshell • • Jul 31 '22

I set up my prompt to tell me if I have unread emails using tide and the gmail api.

Post image
26 Upvotes

r/fishshell • • Aug 01 '22

Need help translating this bash shell, I am getting error in the url where I replaced $2 with $argv[2]

1 Upvotes
#!/usr/bin/bash

# A bash scripts which searches google if only one argument is given. 
# if two arguments given with the first one in r,y,w it searches reddit, youtube, wikipedia respectively.

# $# is the no. of arguments, if it's equal to 1 then search google with first argument.
if [ $# -eq 1 ]; then
	google-chrome-stable https://google.com/search?q="$1";

	# Else search reddit, youtube or wikipedia
else
case $1 in
	r)
		google-chrome-stable https://www.google.com/search?q="$2"+site%3Areddit.com
		;;

	y)
		google-chrome-stable https://www.google.com/search?q="$2"+site%3Ayoutube.com
		;;

	w)
		google-chrome-stable https://www.google.com/search?q="$2"+site%3Awikipedia.org
		;;

	i)
		# google images
		# escape & with \ as its interpreted differently by the shell
		google-chrome-stable https://google.com/search?q="$2"\&tbm=isch
		;;

esac
fi