V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xingheng
V2EX  ›  程序员

求推荐:项目级别的 shell snippet 命令管理工具

  •  1
     
  •   xingheng · 2020-02-12 15:28:04 +08:00 · 1430 次点击
    这是一个创建于 1526 天前的主题,其中的信息可能已经有所发展或是发生改变。

    类似pet, 但是只针对当前项目的常用命令,配置文件可以跟着项目走,可以安装三方依赖。

    能支持二次命令参数替换最好,最好带 interactive 模式。

    第 1 条附言  ·  2020-02-12 17:44:12 +08:00
    环境:macOS & Linux
    6 条回复    2020-03-03 14:18:38 +08:00
    ps1aniuge
        1
    ps1aniuge  
       2020-02-12 16:35:16 +08:00
    可以安装三方依赖----------安装 linux 版 powershell 后,就有 alias 命令。

    [root@ps62 ~]# pwsh
    PowerShell 6.2.4
    Copyright (c) Microsoft Corporation. All rights reserved.

    https://aka.ms/pscore6-docs
    Type 'help' to get help.

    PS /root> get-command *alias*

    CommandType Name Version Source
    ----------- ---- ------- ------
    Cmdlet Export-Alias 6.1.0.0 Microsoft.PowerShell.Utility
    Cmdlet Get-Alias 6.1.0.0 Microsoft.PowerShell.Utility
    Cmdlet Import-Alias 6.1.0.0 Microsoft.PowerShell.Utility
    Cmdlet New-Alias 6.1.0.0 Microsoft.PowerShell.Utility
    Cmdlet Remove-Alias 6.1.0.0 Microsoft.PowerShell.Utility
    Cmdlet Set-Alias 6.1.0.0 Microsoft.PowerShell.Utility

    支持嵌入变量。

    pet 那玩意,你一说你,我刚刚知道,我看了一下,都是小技巧。小 alias。
    ps1aniuge
        2
    ps1aniuge  
       2020-02-12 16:39:16 +08:00
    centos8,debian10,需要安装 powershell-preview。然后把 pwsh-preview,改名成 pwsh。1 个月后,ps7 正式版出了后,就不需要这样做了。



    centos7,centos8,安装 powershell:
    curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/7/prod.repo
    sudo yum remove -y powershell #删除旧版
    sudo yum install -y powershell
    pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
    pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
    pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '



    ubuntu1604:
    sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/16.04/prod.list
    sudo apt-get update
    sudo apt-get remove -y powershell #删除旧版
    sudo apt-get install -y powershell
    pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
    pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
    pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '


    ubuntu1804:
    sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/18.04/prod.list
    sudo apt-get update
    sudo apt-get remove -y powershell #删除旧版
    sudo apt-get install -y powershell
    pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
    pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
    pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '



    debian9:
    sudo apt-get update
    sudo apt-get install curl gnupg apt-transport-https
    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
    sudo apt-get update
    sudo apt-get remove -y powershell #删除旧版
    sudo apt-get install -y powershell
    pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
    pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
    pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '

    debian10:
    sudo apt-get update
    sudo apt-get install curl gnupg apt-transport-https
    curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-buster-prod buster main" > /etc/apt/sources.list.d/microsoft.list
    sudo apt-get update
    sudo apt-get remove -y powershell #删除旧版
    sudo apt-get install -y powershell
    pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
    pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
    pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '
    xingheng
        3
    xingheng  
    OP
       2020-02-12 17:48:18 +08:00
    感觉很别扭啊,为什么我要在*nix 下用 powershell 啊

    alias 还是写入到 shell profile 里面的,我不希望和一些项目相关的命令污染了全局配置。

    还是谢谢你!@ps1aniuge
    ps1aniuge
        4
    ps1aniuge  
       2020-02-14 18:29:39 +08:00
    1 10 年内,powershell 是 shell 的未来。为什么你不在*nix 下用 powershell 啊?

    2 powershell 支持 linux,mac。

    3 powershell 有命令行,可以交互,这一点 py,perl,都不行。

    4 alias 是通过 Export-Alias,写入到你自定义的文件名中。
    又通过 Import-Alias 导入并使用。不会和一些项目相关的命令污染了全局配置。

    5 pet 的命令和 ps 的这些命令功能雷同,只是名字不同:
    Export-Alias,Get-Alias,Import-Alias,New-Alias,Remove-Alias,Set-Alias

    6 powershell 除了有两个 ssl 依赖之外,就是安装在 /opt 下的绿色软件。
    你只用上述命令,不需要 ssl 依赖。所以 ps 对你来说,就是绿色的第三方库。

    7 可以通过扩展内置模块 psreadline 的功能,自定义按某些键盘出某些功能。
    xingheng
        5
    xingheng  
    OP
       2020-03-02 15:06:55 +08:00
    找到了一个还算匹配需求的工具:just,链接: https://github.com/casey/just
    直接基于 sh 运行,没有注入,全平台。
    @ps1aniuge
    ps1aniuge
        6
    ps1aniuge  
       2020-03-03 14:18:38 +08:00
    @xingheng 实际上,我用 ps 已经开发出了,一个小 alias 工具,但是版本要求太高,依赖要求过分,被我废弃了,过些日子等我有空,我再从底层重写一个。敬清期待。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5689 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 88ms · UTC 03:08 · PVG 11:08 · LAX 20:08 · JFK 23:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.