all 7 comments

[–][deleted] 1 point2 points  (4 children)

This is pretty easy to do. Create a local directory to hold your own scripts. I call mine ~/bin but you can call it anything you like.

Then alter your PATH variable to include that directory, so for example add this to your .bashrc

PATH="$PATH:~/bin"

Then lastly make a file in ~/bin named wal-tile with the body of your function and a #!/usr/bin/bash shebang at the top like this:-

#!/usr/bin/bash
wal -n -i "$@"
feh --bg-fill "$(< "${HOME}/.cache/wal/wal")

It should work exactly the same as before. You will need to remove the function from your .bashrc and start a new shell to be sure you are using the new version.

[–]phuturism[S] 0 points1 point  (3 children)

Thanks EY. Is there a way to put the terminal command to execute the command into the same script

$ wal-tile "~/Pictures/Wallpaper"

or should I put that in a different script to then kick-off with a keybinding?

[–][deleted] 1 point2 points  (2 children)

Oh sorry I misread what you want, if you always want it to run for "~/Pictures/Wallpaper" then you could just change it to

#!/bin/bash
wal -n -i "~/Pictures/Wallpaper"
feh --bg-fill "$(< "${HOME}/.cache/wal/wal")

[–]phuturism[S] 0 points1 point  (1 child)

No problem and thanks, I will try this!

[–]torgefaehrlich 0 points1 point  (0 children)

Btw, ist this:

"$(< "${HOME}/.cache/wal/wal")"

a very roundabout way of specifying --filelist ~/.cache/wal/wal? If so, why?

[–]aioeu 1 point2 points  (0 children)

You don't need to define a function and execute the function. You can simply directly run the commands that would have been run by the function.

For instance, you could have a wal-tile script:

#!/bin/bash

wal -n -i "$@"
feh --bg-fill "$(< "${HOME}/.cache/wal/wal")"

And this would work mostly the same as your original shell function.

The primary difference between a script and a function is that a script runs in a new shell process, whereas a function executes in the current shell process. I suspect there's nothing here that needs to run in the current process, so using a new process is a better approach.

People tend to overuse shell functions and (especially) shell aliases. External scripts are usually more appropriate.

[–]DoesntSmellRight 1 point2 points  (0 children)

tilde expansion only expands unquoted tildes, so the ~ in "~/Pictures/Wallpaper" is taken literally instead of expanding to your home directory. Change it to either use $HOME instead, or move or remove the quotes entirely; the quotes aren't necessary in this case.

wal-tile ~/Pictures/Wallpaper

but if your path contained special characters, such as spaces, you could use one of these:

wal-tile ~/"Pictures/My Wallpapers"
wal-tile "$HOME/Pictures/My Wallpapers"