Solved [HELP] Running commands after login (Fish Shell)

Hi folks,

I am sorry for this noob question, but I am pretty novice to FreeBSD and I couldn't find a clear answer but another thread on this same forum, also I guess cross-posting is forbidden.

From that post I read that is recommended modifying a file called ".login". I did the changes but they do not work, I am not sure if it depends because are simply incorrects or because I changed my shell to Fish.

The last two commands are my entries:
Code:
# $FreeBSD$
#
# .login - csh login script, read by login shell, after `.cshrc' at login.
#
# See also csh(1), environ(7).
#

# Query terminal size; useful for serial lines.
if ( -x /usr/bin/resizewin ) /usr/bin/resizewin -z

# Display a random cookie on each login.
if ( -x /usr/bin/fortune ) /usr/bin/fortune freebsd-tips

# WebDav
if ( -x /usr/local/bin/rclone ) /usr/local/bin/rclone mount drive:/ /mnt/drive/ --vfs-cache-mode writes --daemon

# Comp key
if ( -x /usr/local/bin/setxkbmap ) /usr/local/bin/setxkbmap -option compose:rwin

Both commands work fine if launched from the cli.

Thanks in advance, TGL!
 
or because I changed my shell to Fish.
As can be read in the comments of ~/.login, this file is executed by tcsh(1) (or csh(1)) when it's a login shell. Different shells use different script files, sh(1) for example runs ~/.profile, bash(1) runs ~/.profile (because it's a bourne shell it shares many of the same start files) and ~/.bashrc. As far as I've been able to find out the fish shell doesn't execute a start script, except ~/.config/fish/config.fish.

setxkbmap(1) only works in an Xorg session. Put it in your ~/.xinitrc (before the exec that starts your WM or DE) so it's started when you start a Xorg session.
 
SirDice

Thanks for your help.

I checked on the fish online documentation and also in the fish_config webpage but I haven't found (probably missed) such hint.

About setxkbmap I assumed it could work into any terminal emulator but since works with X in this case I am going to use Xfce4 login session to run it.

Cheers, TGL.
 

How do I run a command every login? What's fish's equivalent to .bashrc or .profile?​

Edit the file ~/.config/fish/config.fish 1, creating it if it does not exist (Note the leading period).
1
The "~/.config" part of this can be set via $XDG_CONFIG_HOME, that's just the default.

Blame on me!🤦‍♂️
 
As can be read in the comments of ~/.login, this file is executed by tcsh(1) (or csh(1)) when it's a login shell. Different shells use different script files, sh(1) for example runs ~/.profile, bash(1) runs ~/.profile (because it's a bourne shell it shares many of the same start files) and ~/.bashrc. As far as I've been able to find out the fish shell doesn't execute a start script, except ~/.config/fish/config.fish.

setxkbmap(1) only works in an Xorg session. Put it in your ~/.xinitrc (before the exec that starts your WM or DE) so it's started when you start a Xorg session.
By default, sh(1) also runs ~/.shrc after running ~/.profile. This became particularly noteworthy to me starting with FreeBSD version 13, because, unlike in previous versions, the default version of ~/.shrc now resets the PS1 prompt. Therefore, if one wants to modify the PS1 prompt in sh(1), one must modify ~/.shrc or it will override any such changes one might make in ~/.profile (and yes, I learned this the hard way).
 
Eventually I got an help even though I figured out the same solution after reading the documentation hundred times:

Code:
if status is-interactive
    # Commands to run in interactive sessions can go here
    #
   
    # Start WebDav
    function drive
        set tst (find /mnt/drive -maxdepth 0 -empty)
        set mnt '/mnt/drive'
        if test "$tst" = "$mnt"
            command rclone mount drive:/ /mnt/drive/ --vfs-cache-mode writes --daemon &
        else
            true
        end
    end
   
    drive &
    # end WebDav  
end

However the same person that helped me also pointed out that mounting the webdav at that stage isn't the best solution, but where and when should it be mounted then? 🤷‍♂️
 
I am not sure about the "when" but about the "where". /mnt is for temporary mounting. Just generate a /media/drive directory or so. Please see hier(7) for additional information about the best practice directory structure.
 
chrbr

Sorry for being so generic.

I meant that maybe mounting/checking the webdav resource every time I must open a shell/terminal is not clever.
I read that I could use a cron job with the direction "@reboot" thus I could use something like:

Code:
@reboot sleep 30 && rclone mount drive:/ /mnt/drive/ --vfs-cache-mode writes --daemon &
 
Dear tgl,
there is no need to say sorry for being generic. I have just a manual work flow for webdav because I use the resource only from time to time. The @reboot method is perfect for things to be started each boot. It took me also some time until I picked it up from somewhere. The bag of tricks available with FreeBSD tools is almost infinite :).
 
Back
Top