代码之家  ›  专栏  ›  技术社区  ›  armandino

如何定义鱼壳中的别名?

  •  152
  • armandino  · 技术社区  · 15 年前

    我想在fish中定义一些别名。显然应该可以用

    ~/.config/fish/functions
    

    但当我重新启动shell时,它们不会自动加载。有什么想法吗?

    9 回复  |  直到 7 年前
        1
  •  272
  •   hoijui    7 年前

    只使用 alias . 下面是一个基本示例:

    # Define alias in shell
    alias rmi "rm -i"
    
    # Define alias in config file
    alias rmi="rm -i"
    
    # This is equivalent to entering the following function:
    function rmi
        rm -i $argv
    end
    
    # Then, to save it across terminal sessions:
    funcsave rmi
    

    最后一个命令创建文件 ~/.config/fish/functions/rmi.fish .

    感兴趣的人可能想在 the official manual .

        2
  •  108
  •   Jerub    15 年前

    这就是我如何定义一个新函数 foo ,运行它,并持续保存它。

    sthorne@pearl~> function foo
                        echo 'foo was here'
                    end
    sthorne@pearl~> foo
    foo was here
    sthorne@pearl~> funcsave foo
    
        3
  •  48
  •   glenn jackman    11 年前

    对于后代来说,鱼的别名只是功能:

    $ alias foo="echo bar"
    $ type foo
    foo is a function with definition
    function foo
        echo bar $argv; 
    end
    

    删除它

    $ unalias foo
    /usr/bin/unalias: line 2: unalias: foo: not found
    $ functions -e foo
    $ type foo
    type: Could not find “foo”
    
        4
  •  14
  •   seaslee    13 年前
    1. 如果没有 组态鱼 在里面 ~/.config/鱼/ 做吧。
    2. 在那里你可以编写你的函数。 function name command end
        5
  •  13
  •   martisj    12 年前

    将文件另存为 ~/.config/fish/functions/{some_function_name}.fish 当你开始钓鱼的时候,它们应该被自体移植。

        6
  •  9
  •   jww avp    11 年前

    从正确加载函数 ~/.config/fish/函数

    您只能设置 文件中的函数和名称文件与函数名+add.fish扩展名相同。

    这样,在打开的终端中更改文件内容重新加载功能(注意,可能会出现一些延迟~1-5s)

    如果你用命令行编辑

    function name; function_content; end
    

    然后

    funcsave name
    

    您在控制台中有用户定义的函数,并按相同的顺序自定义。

        7
  •  8
  •   CookAtRice    8 年前

    fish首先执行~/.config/fish/config.fish中的命令。 如果它不存在,您可以创建它。

    步骤1。生成配置文件(如.bashrc)

    组态鱼

    步骤2。就这样写你的别名;

    别名rm=“rm-i”

        8
  •  1
  •   Mike    8 年前

    在~/.config/fish/functions中创建一个名为mkalias.fish的函数并将其放入

    function mkalias --argument key value
      echo alias $key=$value
      alias $key=$value
      funcsave $key
    end
    

    这将自动创建别名。

        9
  •  0
  •   sametcodes Tetramputechture    7 年前

    正常开放 vim .config/fish/conf.d/omf.fish ,绑定bash定义并重新启动fish终端。