zoukankan      html  css  js  c++  java
  • [bash] 编写7zz函数替换7z压缩命令

    安装 p7zip 然后将下面内容放到 ~/.zshrc 或者 ~/.bashrc

    function 7zz() {
        # compress a direcotry to directory.7z
        # usage: 7zz path/to/directory [7z options]
        # returns: 0 - successful, 1 - argument error, 2 - not found 7z command
        local ok=$(command -v 7z >/dev/null 2>/dev/null && echo 'ok' || echo '')
        if [ "$ok" != "ok" ]; then
            echo 'not found 7z command, please install p7zip'
            return 2
        fi
    
        local dir="$1"
        local target="$(basename ${dir%/}.7z)"
        if [ ! -d "$dir" ]; then
            echo 'argument error
    usage: 7zz path/to/directory [7z options]'
            return 1
        fi
        if [ -f "$target" ]; then
            while true; do
                printf "Are you sure overwrite file "$target"? [y/N] "
                read yn
                case $yn in
                [yY][eE][sS] | [yY]) break ;;
                [nN][oO] | [nN] | "") return 0 ;;
                *) ;;
                esac
            done
            rm -f "$target"
        fi
    
        shift
        7z a -mx=9 -xr!.DS_Store "$@" "$target" "$dir"
    }

    然后打开新会话或者重新载入配置文件

    source ~/.zshrc

    或者

    source ~/.bashrc

    命令格式:

    7zz 目录 [7z的参数]

    例子1:压缩 abc 目录为 abc.7z

    7zz abc

    例子2: 压缩vscode的扩展目录,并且排除cocos扩展,重命名为vscode_extensions.7z

    7zz ~/.vscode/extensions -xr!cocos-creator -xr!cocos-debug && mv {,vscode_}extensions.7z

  • 相关阅读:
    Longest Substring Without Repeating Characters
    Longest Valid Parentheses
    LInux下编译发生的libc相关错误
    【转载】字符编码笔记:ASCII,Unicode和UTF-8
    Python深入:super函数
    Python基础:常用函数
    25最小操作数问题
    24字符串最短编辑距离
    23最大乘积子串
    22倒排索引简介
  • 原文地址:https://www.cnblogs.com/Bob-wei/p/12841716.html
Copyright © 2011-2022 走看看