Некоторые демоны не записывали журналы в /var/log/
в Arch Linux, и конфигурация для syslog-ng
отличается от других ответов, которые я видел.
Обычной службы syslog-ng.service
здесь нет, вместо этого она называется syslog-ng@default.service
.
Это не сработает:
# systemctl enable syslog-ng
Failed to enable unit: Unit file syslog-ng.service does not exist.
Я должен сделать это немного иначе, согласно Arch Wiki:
# systemctl start syslog-ng@default.service
# systemctl enable syslog-ng@default.service
Created symlink /etc/systemd/system/multi-user.target.wants/syslog-ng@default.service → /usr/lib/systemd/system/syslog-ng@.service.
#
Вы можете установить pacman -S pkgfile
, выполнить sudo pkgfile --update
и добавить это в свой~/.bashrc
:
source /usr/share/doc/pkgfile/command-not-found.bash
из Arch Wiki:
Then attempting to run an unavailable command will show the following info:
$ abiword
abiword may be found in the following packages: extra/abiword 3.0.1-2 /usr/bin/abiword
Это не будет искать похожие команды.
Существует также команда AUR -не -найденный пакет , который обещает больше, но в настоящее время помечен как устаревший. Вы можете связаться с автором на github (https://github.com/metti/command-not-found).
Поскольку я не нашел доступных прямо сейчас пакетов, реализующих это для Arch Linux, я попытался собрать решение для того же самого.
Для этого решения мы используем переменную PROMPT_COMMAND
и compgen
.
Шаги
temp.py
. #!/usr/bin/env python
import sys
def similar_words(word):
"""
return a set with spelling1 distance alternative spellings
based on http://norvig.com/spell-correct.html
"""
alphabet = 'abcdefghijklmnopqrstuvwxyz-_0123456789'
s = [(word[:i], word[i:]) for i in range(len(word) + 1)]
deletes = [a + b[1:] for a, b in s if b]
transposes = [a + b[1] + b[0] + b[2:] for a, b in s if len(b) > 1]
replaces = [a + c + b[1:] for a, b in s for c in alphabet if b]
inserts = [a + c + b for a, b in s for c in alphabet]
return set(deletes + transposes + replaces + inserts)
def bash_command(cmd):
import subprocess
sp = subprocess.Popen(['/bin/bash', '-c', cmd], stdout=subprocess.PIPE)
return [s.decode('utf-8').strip() for s in sp.stdout.readlines()]
def main():
word = sys.argv[1]
command_list = bash_command('compgen -ck')
result = list(set(similar_words(word)).intersection(set(command_list)))
if len(result) > 0:
wrong_command_str = "Did you mean?"
indent = len(wrong_command_str)//2
print("Did you mean?")
for cmd in result:
print(indent*" ",cmd)
if __name__ == '__main__':
main()
$PROMPT_COMMAND
. export PROMPT_COMMAND='if [ $? -gt 0 ]; then python test.py $(fc -nl | tail -n 1 | awk "{print $1}"); fi;'$PROMPT_COMMAND
$? -gt 0
fc -nl | tail -n 1 | awk "{print $1}"
python test.py <command-name>