为什么使用 Fish shell 时 snap 包会消失?

Ken*_*der 7 wayland fish snap

如果我全新安装 Ubuntu 17.10,通过 snap 安装一个包,然后将我的 shell 更改为 fish,再次登录后,gnome-shell 的菜单和我的收藏夹列表中缺少该包。

奇怪的是,这也只发生在使用 Wayland 时。

什么可能导致这个问题?我可以确认我的shell正常工作并且路径正常。我还可以通过 snap run 或其命令行版本确认这些应用程序运行良好,但就好像 *.desktop 文件丢失一样。

小智 7

如果不存在则创建~/.config/fish/config.fish,并添加以下两行

set PATH /var/lib/snapd/snap/bin $PATH
set XDG_DATA_DIRS /var/lib/snapd/desktop/:$XDG_DATA_DIRS
Run Code Online (Sandbox Code Playgroud)

这会将快照应用程序放在您的路径上并使您的快捷方式图标可用。


小智 5

问题:该问题与您的登录外壳有关。

变量XDG_DATA_DIRS/etc/profile.d来源 ( /etc/profile.d/apps-bin-path.sh)时设置

但是如果你使用fish-shell,就像你的情况一样,或者zsh,你没有采购/etc/profile.d/,因此XDG_DATA_DIRS永远不会设置.desktop/var/lib/snapd/desktop也找不到文件。这不是错误,而是因为 fish 与 POSIX 1003.1 不兼容。这意味着这些 shell 不理解 bash 语法。

解决方法:

我可以想到至少两种解决方法。

  1. 最简单的方法是将默认 shell 反转为 bash

    chsh -s /bin/bash
    
    Run Code Online (Sandbox Code Playgroud)

    然后添加行

    fish 
    
    Run Code Online (Sandbox Code Playgroud)

    ~/.bashrc. 通过这样做,您的登录 shell 将是 bash 并且您/etc/profile.d将获得源代码,但是每次打开终端时您都会使用 fish。在终端上写“退出”会跳回 bash。

  2. 一个最棘手的方法是将 fish 作为您的登录 shell,但强制使用/etc/profile.d它的来源。为此,您需要执行以下步骤:

    1. 从你的fish shell 安装fisher 和bass(使Bash 实用程序在Fish shell 中可用)。

      curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs https://git.io/fisher 
      
      # instruct fisher to download the bass package   
      fisher add edc/bass 
      
      Run Code Online (Sandbox Code Playgroud)
    2. 编辑您的~/.config/fish/config.fish(如果它不存在则创建它)并/etc/profile.d使用bass 获取每个文件。

      nano ~/.config/fish/config.fish
      
      Run Code Online (Sandbox Code Playgroud)

      (在另一端ls/etc/profile.d directory得到的文件列表。复制它们)

      将列表粘贴到您的 nano 终端中,如下所示:

      bass source /etc/profile.d/apps-bin-path.sh 
      
      bass source /etc/profile.d/cedilla-portuguese.sh 
      
      bass source /etc/profile.d/vte-2.91.sh 
      
      bass source /etc/profile.d/bash_completion.sh 
      
      bass source /etc/profile.d/input-method-config.sh 
      
      bass source /etc/profile.d/xdg_dirs_desktop_session.sh 
      
      Run Code Online (Sandbox Code Playgroud)

      保存、关闭、关闭会话或重新启动和“ta-da”。

    使用此选项,您可以将 fish 作为登录 shell,但您必须不时检查/etc/profile.d目录以确保没有您未采购的新文件。