AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-56505

fauve's questions

Martin Hope
fauve
Asked: 2025-02-03 01:54:47 +0800 CST

Zsh 的变量自动完成选项

  • 6

总体概述

我必须在 zsh 中为命令设置值自动完成(在下面的最小示例中,我将使用 进行展示testcmd)。因此,我当前的代码可以很好地处理硬编码值:

当前自动完成代码(起作用的代码)

function testcmd()
{
    echo "Nothing to do, just a test command"
}


_test_complete() {
    _values \
        "Possible values" \
        foo'[Foo]' \
        bar'[Bar baz]' \
}

compdef _test_complete testcmd

当前的自动完成行为

当我输入时testcmd <tab>,我正确地得到了以下所需的渲染:

$ testcmd
Possible values
bar  -- Bar baz
foo  -- Foo

我想要达到的目标是什么

但是正如您所看到的,这些值在函数内部是硬编码的,理想情况下,函数应该从变量中检索它们。

我已经尝试过

因此很自然地,我将值放入变量中,values_variable如下所示:

已尝试的代码(无效的代码)

function testcmd()
{
    echo "Nothing to do, just a test command"
}


_test_complete() {
    local values_variable
    values_variable="foo'[Foo]' \
        bar'[Bar baz]' \ "
    _values \
        "Possible values" \
        ${values_variable}
}

compdef _test_complete testcmd

已尝试代码的行为

但是当我尝试时testcmd <tab>它完全失败了:

$ testcmd
_values:compvalues:11: invalid value definition: foo'[Foo]' \t\tbar'[Bar baz]' \
_values:compvalues:11: invalid value definition: foo'[Foo]' \t\tbar'[Bar baz]' \
_values:compvalues:11: invalid value definition: foo'[Foo]' \t\tbar'[Bar baz]' \
$ testcmd 

我还做了什么

  • 我试图用 来逃避这些空间echo ${values_variable} | sed "s/ /\\ /g" ;
  • 我尝试使用$values_variable命令eval来假装它的内容直接在定义中输入_values;
  • 我尝试了两者eval并逃脱eval $(echo ${values_variable} | sed "s/ /\\ /g") ;
  • 我尝试用循环逐行显示:
echo "$values_variable" | while read -r line; do
    eval "$line"
  done
  • 扩展与${(@f)values_variable}̀ ;
  • 还有很多其他的想法。但是都失败了。

我找到的最接近的解决方案

在 如何使用to (zsh 补全) tread传递文件内容cat_values中,我找到了从外部文件导入值的解决方案,但用户似乎面临着相同的空格转义问题。但是,我无法将其调整为内部变量的情况$values_variables。

我自然尝试了这个,但它也不起作用:

_test_complete() {
    local values_variable
    values_variable="foo'[Foo]' \
        bar'[Bar baz]' \ "
    OLD_IFS=$IFS
    IFS=$'\n'
    _values \
        "Possible values" \
        ${values_variable}
    IFS=$OLD_IFS
}

问题

_values如何从变量加载要提供给自动完成函数内部的值?

zsh
  • 1 个回答
  • 37 Views
Martin Hope
fauve
Asked: 2024-07-22 03:20:58 +0800 CST

zsh 参数值自动完成

  • 6

总体概述

这是我的自动肤色文件:

_triumphum_complete() {
_arguments \
  '(- 1 *)'{-h,--help}'[show help options]' \
  '(- 1 *)--tui[Run the game selection interface]' \
  '(- 1 *)'{-r,--run}'[Run a given game and track playing time.]' \
  '(- 1 *)'{-a,--about}'[Show about message.]' \
  '(- 1 *)'{-d,--donate}'[Open link to give a tip.]' \
  '(- 1 *)--no-splash[Do not show splash at opening.]' \
  '(- 1 *)--list-games[Afficher la liste des jeux.]' \
  '(- 1 *)--list-licences[Afficher la liste des licences.]' \
  '(- 1 *)--list-genres[Afficher la liste des genres de jeu.]' \
  '(- 1 *)--list-platforms[Afficher la liste des genres des plateformes.]' \
  '(- 1 *)'{-c,--config-file}'[Select different config file from default one.]' \
  '(- 1 *)'{-g,--games}'[Select different game file from default one.]' \
  '(- 1 *)'{-p,--platforms}'[Select different platform file from default one.]' \
  '(- 1 *)'{-l,--licences}'[Select different licence file from default one.]' \
  '(- 1 *)'{-t,--game-genres}'[Select different game genre file from default one.]' \
  '(- 1 *)--layout[Utiliser des raccourcis dactyliques adaptés à la disposition de clavier.]' \
  '(- 1 *)--add-game[Ajouter un nouveau jeu.]' \
  '(- 1 *)--add-licence[Ajouter une nouvelle licence.]' \
  '(- 1 *)--add-genre[Ajouter un nouveau genre de jeu.]' \
  '(- 1 *)--add-platform[Ajouter une nouvelle plateforme.]' \
  '(- 1 *)--del-game[Suprimer un jeu.]' \
  '(- 1 *)--del-licence[Suprimer une licence.]' \
  '(- 1 *)--del-genre[Suprimer un genre de jeu.]' \
  '(- 1 *)--del-platform[Suprimer une plateforme.]' \
}

compdef _triumphum_complete triumphum

它的渲染与目标相匹配,如您所见:

% % triumphum -<tab>
option
--about           -a  -- Show about message.
--add-game            -- Ajouter un nouveau jeu.
--add-genre           -- Ajouter un nouveau genre de jeu.
--add-licence         -- Ajouter une nouvelle licence.
--add-platform        -- Ajouter une nouvelle plateforme.
--config-file     -c  -- Select different config file from default one.
--del-game            -- Suprimer un jeu.
--del-genre           -- Suprimer un genre de jeu.
--del-licence         -- Suprimer une licence.
--del-platform        -- Suprimer une plateforme.
--donate          -d  -- Open link to give a tip.
--game-genres     -t  -- Select different game genre file from default one.
--games           -g  -- Select different game file from default one.
--help            -h  -- show help options
--layout              -- Utiliser des raccourcis dactyliques adaptés à la disposition de clavier.
--licences        -l  -- Select different licence file from default one.
--list-games          -- Afficher la liste des jeux.
--list-genres         -- Afficher la liste des genres de jeu.
--list-licences       -- Afficher la liste des licences.
--list-platforms      -- Afficher la liste des genres des plateformes.
--no-splash           -- Do not show splash at opening.
--platforms       -p  -- Select different platform file from default one.
--run             -r  -- Run a given game and track playing time.
--tui                 -- Run the game selection interface

但是,我想专门为--run应该仅作为值的选项添加一个自动完成功能{"crash", "civilization", "vicecity"}。

我做了什么

我已经尝试制作一个特定的自动完成功能triumphum --run并将其单独匹配:

_triumphum_run_games() {
    local games=('civilization' '0ad' 'vicecity' 'crash')
    _arguments 'game' games
}
compdef _triumphum_run_games "triumphum --run"   

但它不起作用。

问题

如何专门添加自动肤色triumphum --run?

shell
  • 1 个回答
  • 19 Views
Martin Hope
fauve
Asked: 2024-03-30 21:06:00 +0800 CST

使用 fetchmail 仅检索一个特定帐户的邮件

  • 6

情况

我有以下内容~/.fetchmailrc

poll pop.gmail.com       protocol pop3 user "[email protected]"      password "***"            ssl
mda "/usr/bin/procmail -d default -a foo@example-com"

poll pop.gmail.com       protocol pop3 user "[email protected]"      password "***"            ssl
mda "/usr/bin/procmail -d default -a bar@example-com"

因此,我检索所有带有fetchmail -v -m '/usr/bin/procmail -d %T'.

问题

但问题是所有账户都被找回了。

问题

fetchmail 命令是否可以要求仅检索一个特定地址的邮件?

email
  • 1 个回答
  • 34 Views
Martin Hope
fauve
Asked: 2023-06-06 08:03:10 +0800 CST

用 setxkbmap pageUp 和 pageDown 交换

  • 5

在 Debian 上,我尝试将 setxkbmap pageDown 与 pageUp(以及 Home 和 End)交换,但我没有在选项中找到执行此操作的选项-option。

我尝试类似setxkbmap -layout fr -variant bepo -option caps:swapescape compose:menu terminate:ctrl_alt_bksp pgup:pgdn,但<key0>:<key1>不是交换键的语法。

那么如何交换这些密钥呢?

keyboard-shortcuts
  • 1 个回答
  • 11 Views
Martin Hope
fauve
Asked: 2022-09-24 15:58:09 +0800 CST

aptitude 升级错误警告 #1019855 和 #1019564

  • 2

我尝试升级 Debian Bullseye,但我收到了一条焦虑的警告消息:

 % sudo aptitude upgrade
Resolving dependencies...
The following NEW packages will be installed:
  linux-headers-5.10.0-18-amd64{a} linux-headers-5.10.0-18-common{a} linux-image-5.10.0-18-amd64{a}
The following packages will be REMOVED:
  sse3-support{u}
The following packages will be upgraded:
  avahi-autoipd avahi-daemon base-files bind9-dnsutils bind9-host bind9-libs chromium chromium-common chromium-sandbox clamav clamav-base clamav-freshclam cri-tools curl dpkg dpkg-dev
  fig2dev firefox-esr firefox-esr-l10n-fr fonts-opensymbol gir1.2-ayatanaappindicator3-0.1 gir1.2-gdkpixbuf-2.0 gir1.2-javascriptcoregtk-4.0 gir1.2-lokdocview-0.1 gir1.2-webkit2-4.0
  gping grub-common grub-pc grub-pc-bin grub2-common krb5-locales kubeadm kubectl kubelet kubernetes-cni libavahi-client3 libavahi-common-data libavahi-common3 libavahi-compat-libdnssd1
  libavahi-core7 libavahi-glib1 libayatana-appindicator1 libayatana-appindicator3-1 libc-bin libc-dev-bin libc-devtools libc-l10n libc6 libc6-dev libclamav9 libcurl3-gnutls libcurl4
  libdatetime-timezone-perl libdpkg-perl libexpat1 libexpat1-dev libgdk-pixbuf-2.0-0 libgdk-pixbuf-2.0-dev libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgssapi-krb5-2
  libhttp-daemon-perl libhttp-parser2.9 libjavascriptcoregtk-4.0-18 libjs-bootstrap4 libjuh-java libjurt-java libk5crypto3 libkrb5-3 libkrb5support0 liblibreoffice-java
  liblibreofficekitgtk libnss-myhostname libnss-systemd libpam-systemd libpcre2-16-0 libpcre2-32-0 libpcre2-8-0 libpcre2-dev libpcre2-posix2 libpoppler-cpp0v5 libpoppler-glib8
  libpoppler-qt5-1 libpoppler102 libpq5 libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3
  libreoffice-help-common libreoffice-help-en-us libreoffice-help-fr libreoffice-impress libreoffice-l10n-fr libreoffice-math libreoffice-style-colibre libreoffice-style-elementary
  libreoffice-writer libreofficekit-data libridl-java libsystemd0 libudev1 libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3
  libunoloader-java libwebkit2gtk-4.0-37 libxnvctrl0 libxslt1.1 linux-compiler-gcc-10-x86 linux-headers-amd64 linux-image-amd64 linux-kbuild-5.10 linux-libc-dev locales poppler-utils
  publicsuffix python3-uno systemd systemd-sysv systemd-timesyncd thunderbird tzdata udev uno-libs-private ure virtualbox virtualbox-dkms virtualbox-qt zlib1g zlib1g-dev
The following packages are RECOMMENDED but will NOT be installed:
  libnss-nis libnss-nisplus
136 packages upgraded, 3 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B/540 MB of archives. After unpacking 400 MB will be used.
Do you want to continue? [Y/n/?] y
Retrieving bug reports... Done
Parsing Found/Fixed information... Done
critical bugs of libc6 (2.31-13+deb11u3 -> 2.31-13+deb11u4) <Outstanding>
 b1 - #1019855 - Fwd: libc6: immediately crashes with SIGILL on 4th gen Intel Core CPUs (seems related to AVX2 instructions), bricking the whole system
grave bugs of grub-pc (2.04-20 -> 2.06-3~deb11u2) <Outstanding>
 b2 - #1019564 - (during upgrade) grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels.  This is not supported yet..
Summary:
 libc6(1 bug), grub-pc(1 bug)
Are you sure you want to install/upgrade the above packages? [Y/n/?/...]

那么,libc6 和 grub-pc 是怎么回事,问题是否像 apt 所说的那样危险?具体会发生什么?顺便说一句,我可以说“是”并继续前进吗?

debian grub
  • 1 个回答
  • 54 Views
Martin Hope
fauve
Asked: 2022-02-26 12:24:27 +0800 CST

我怎样才能暂停|休眠一段时间

  • 1

我尝试按照以下规则为笔记本电脑的合上盖子提供一种行为:

当盖子关闭时:

  1. 1m后,应该是锁屏的;
  2. 10m后应暂停;
  3. 15m后应关机。

因此,我制作了以下脚本:

#!/bin/bash
 
USER=fauve
 

sleep 1m
# set screensaver
su -c  "$HOME/.local/bin/screenlock" - $USER

# hibernate
sleep 9m
systemctl suspend


sleep 5m
# shutdown
shutdown 0

但正如您所看到的,shutdown当笔记本电脑处于暂停状态时,它就永远不会关闭。

那么如何编程暂停或关闭 5 分钟,然后让脚本继续完全关闭计算机?

laptop suspend
  • 1 个回答
  • 264 Views
Martin Hope
fauve
Asked: 2018-06-20 23:18:37 +0800 CST

在 shell 函数中查找

  • 2

我尝试放入find函数内部并使用以下最小工作示例捕获传递给该函数的参数:

功能 DO
{
    ls $(find . -type f -name "$@" -exec grep -IHl "TODO" {} \;)
}

但是,当我执行时DO *.tex,我得到“查找:路径必须在表达式之前:”。但是当我直接这样做时:

ls $(find . -type f -name "*.tex" -exec grep -IHl "TODO" {} \;)

然后我得到所有包含“TODO”的TeX文件。

我在函数中尝试了很多东西DO,例如\"$@\", '$@',我更改了引号,但行为仍然相同。

那么,如何强制在函数内部找到工作?

bash alias
  • 2 个回答
  • 525 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve