3 个不稳定版本

0.2.0 2019 年 5 月 15 日
0.1.4 2021 年 1 月 18 日
0.1.0 2019 年 3 月 19 日

#2415 in 命令行实用工具

412 星 & 8 关注者

自定义许可证

42KB
815

pier ~ Linux 脚本管理工具

Build Status crates.io

一个中心仓库,用于管理您所有的单行命令、脚本、工具和 CLI。添加、删除、列出和运行脚本 - 存储元数据以便以后轻松查找。不再需要挖掘您的 bin 文件夹...

Boat pier

描述

如果您在终端中花费过任何时间,无疑已经积累了一大批单行命令、脚本、有用的工具和 CLI。每次您想使用它们时,都需要翻遍您的 bin 文件夹,试图回忆起脚本的名称... Linux 用户喜欢难以记住的命名约定。

脚本应该是第一等公民。在 GUI 世界中,我们可以通过某种菜单找到我们的程序。在终端中,脚本会丢失。

Pier 的理念是为所有脚本创建一个中心仓库,并提供一种方式来附加有关这些脚本的信息。使用 Pier,您可以添加、删除、列出和运行脚本。这些脚本可以通过可读的 TOML 配置文件由 Pier 管理,或者您可以使用它来编目您可能散落在各处的现有脚本 - 然后,您只需添加特定脚本的元数据,并将其附加到 PATH 中的名称。

安装

Crates.iocargo install pier

GitHub 发布版:只需下载发布版二进制文件

使用 Nix 软件包管理器

  1. 从GitHub发布版:make installnix-env -if derivation.nix
  2. 从源代码:更新派生中的 src./.

近期重大更改

版本 0.1.4

配置变量 default_interpreter 已被 移除

default_interpreter = ["foorunner", "-c"]

因此,当从早期版本升级到 0.1.4 时,您需要以以下格式指定变量

[default]
interpreter = ["foorunner", "-c"]

操作

使用 pier --help 在命令行中显示帮助或查看 src/cli.rs 以获取更详细的说明。

pier 0.1.4
Benjamin Scholtz, Isak Johansson
A simple script management CLI

USAGE:
    pier [FLAGS] [OPTIONS] <alias>
    pier [FLAGS] [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help       
            Prints help information

    -V, --version    
            Prints version information

    -v, --verbose    
            The level of verbosity


OPTIONS:
    -c, --config-file <path>    
            Sets a custom config file.
            
            DEFAULT PATH is otherwise determined in this order:
            
            - $PIER_CONFIG_PATH (environment variable if set)
            
            - pier.toml (in the current directory)
            
            - $XDG_CONFIG_HOME/pier/config.toml
            
            - $XDG_CONFIG_HOME/pier/config
            
            - $XDG_CONFIG_HOME/pier.toml
            
            - $HOME/.pier.toml
            
            - $HOME/.pier
            
             [env: PIER_CONFIG_PATH=]

ARGS:
    <alias>    
            The alias or name for the script.


SUBCOMMANDS:
    add       Add a new script to config.
    edit      Edit a script matching alias.
    help      Prints this message or the help of the given subcommand(s)
    list      alias: ls - List scripts
    remove    alias: rm - Remove a script matching alias.
    run       Run a script matching alias.
    show      Show a script matching alias.
  • pier list
  • pier add"ip link set wlp58s0 down && sleep 5 && ip link set wlp58s0 up" --alias refresh-wifi
  • pier refresh-wifi

示例 pier TOML 配置

[scripts.refresh-wifi]
command = "ip link set wlp58s0 down && sleep 5 && ip link set wlp58s0 up"

[scripts.twa-analyze]
command = "docker run --rm -t trailofbits/twa -vw"
tags = [ "infosec" ]

[scripts.enabled-services]
command = "systemctl list-unit-files --state=enabled"

[scripts.flush-docker]
command = "docker container stop $(docker container ls -a -q) && docker system prune -a -f --volumes"
description = "A script to clear out old Docker containers and images"
tags = [ "docker", "flush" ]

示例 pier list 输出

▶ pier list           
 Alias             | Command 
-------------------+----------------------------------------------------------------------------------------------------------------
 fromscratch       | appimage-run ~/AppImage/FromScratch.1.4.3.AppImage 
 nspawn-bionic     | sudo systemd-nspawn --bind=/tmp/.X11-unix -D /var/lib/machines/bionic --bind /home/bscholtz:/home/bscholtz 
 bspwm-refresh     | .config/bspwm/bspwmrc 
 flush-docker      | docker container stop $(docker container ls -a -q) && docker system prune -a -f --volumes 
 zfs-compression   | sudo zfs get all | grep compressratio 
 mongo-docker      | docker run --name mongodb -d mongo:latest 
 forward-mongo     | kubectl port-forward mongo-molecule-set-0 27018:27017 
 refresh-wifi      | ip link set wlp58s0 down && sleep 5 && ip link set wlp58s0 up 
 lepton            | appimage-run ~/AppImage/Lepton-1.8.0-x86_64.AppImage 
 ledger            | appimage-run AppImage/ledger-live-desktop-1.6.0-linux-x86_64.AppImage 
 reload-urxvt      | xrdb ~/.Xresources 
 kill-docker       | rm -rf /var/lib/docker 
 reload-xresources | xrdb ~/.Xresources 
 graphiql          | appimage-run ~/AppImage/graphiql-app-0.7.2-x86_64.AppImage 
 enabled-services  | systemctl list-unit-files --state=enabled 
 ports             | netstat -tulpn 
 chmod-copy        | chmod --reference= 
 zfs-drop-caches   | sync; echo 2 | sudo tee /proc/sys/vm/drop_caches 
 update            | sudo nix-channel --update && sudo nixos-rebuild switch 
 flush-untagged    | docker images -q --filter dangling=true | xargs -r docker rmi 
 twa-analyze       | docker run --rm -t trailofbits/twa -vw 
 parity-ubuntu     | docker image pull yodascholtz/parity-ubuntu:latest && docker run -p 8545:8545 yodascholtz/parity-ubuntu:latest

在任意解释语言中执行 pier 脚本

以 shebang 开头的脚本 #! 将使用指定的解释器运行,就像在普通脚本中一样。Pier 通过创建一个临时文件从您的脚本中执行它,然后最终清理文件。这使得您可以在 Python、node.js 等语言中编写 pier 脚本,甚至可以使用像 scriptisto 这样的工具运行编译过的语言。

Shebang 示例配置

[scripts.run_rust_script]
command = '''
#!/usr/bin/env scriptisto

// scriptisto-begin
// script_src: src/main.rs
// build_cmd: cargo build --release && strip ./target/release/script
// target_bin: ./target/release/script
// files:
//  - path: Cargo.toml
//    content: |
//     package = { name = "script", version = "0.1.0", edition = "2018"}
//     [dependencies]
// scriptisto-end


fn main() {
    println!("This is a rust script!");
}

'''

[scripts.run_python]
command = '''
#!/usr/bin/env python3
import sys

print("Running python with version {}".format(sys.version))

'''

设置默认的 shell / 解释器

默认情况下,如果没有指定 shebang,pier 将尝试使用您的默认 shell 来执行脚本。这可以通过解释器变量来覆盖。它需要是一个包含第一个项目为二进制文件,其余为必要标志的列表。

默认解释器示例配置

# Sets the default interpreter, the first item in the list should be the binary and the rest are the arguments for the interpreter cli option.
[default]
interpreter = ["node", "-e"]

# Runs as the fallback interpreter nodejs as it's lacking a shebang
[scripts.hello_world_nodejs]
command = '''
console.log("Hello world!")

'''

# This will be run as a posix sh script as it has a shebang
[scripts.a_shell_script]
command = '''
#!/bin/sh

nohup st > /dev/null 2>&1&

'''

起源

最初打算作为一种管理 Docker 单行脚本的方法,名称 pier 沿着同样的海事主题。我意识到 Pier 可以管理比 Docker 脚本多得多的东西。

通往 v1.0.0 的路线图

  • 模糊搜索 + 自动完成,例如提示别名
  • 完整基本功能:mv,tag
  • 重构测试
  • 更新文档,例如贡献指南、模板

星历史

Star History Chart

依赖关系

~6–15MB
~189K SLoC