Полностью выполнить команду относительно другого каталога

Del código fuente -:gnome -el reloj parece usar dos archivos de sonido -:

  • completo.oga
  • alarma -reloj -transcurrido.oga

En mi sistema, estos archivos están en la carpeta /usr/share/sounds/freedesktop/stereo.

Por lo tanto, podría hacer una copia de seguridad -de los dos archivos de sonido -originales y reemplazarlos por otros archivos de sonido -(preferiblemente de la misma carpeta ).

2
30.06.2019, 20:38
1 ответ

Вот что у меня есть. Это не идеально, но:

  • завершено относительно целевого каталога;
  • автоматический сбой, если целевой каталог не существует;
  • пропустить chpwdи chpwd_functionsи думаю восстановить их правильно;
  • восстановить текущий каталог, если завершение отменено.

Он выглядит сложным и хрупким, поэтому я не совсем уверен в крайних случаях. Известные проблемы:

  • Завершение не всегда добавляет символ суффикса (, такой как пробел, или /для каталога. Например, вкладкаcd1 / echo /biвставляет n/, ноcd1 / echo biвкладка вставляет только n(, тогда какecho biвкладка вставляетn/).
  • Если исходный каталог переименовывается во время операции завершения, оболочка возвращается в новый каталог со старым именем, а не в старый каталог с новым именем.
#compdef cd1 cd1_glob
# cd for one command

_cd1_in () {
  setopt local_options local_traps
  # Cleanup:
  # * Restore the old directory. We do this only if cd succeeded beause
  #   the restoration can do the wrong thing in corner cases (renamed
  #   directory).
  # * Restore the chpwd hook function and the hook array.
  trap 'if ((_cd1_cd_succeeded)); then cd $OLDPWD; fi
        if [[ -n $_cd1_chpwd_function ]]; then
          functions[chpwd]=$_cd1_chpwd_function
        fi
       ' EXIT INT
  builtin cd $words[2] 2>/dev/null || { _cd1_cd_succeeded=0; return 1; }
  shift 2 words; ((CURRENT -= 2))
  _normal
}

_cd1 () {
  if ((CURRENT > 2)); then
    setopt local_options no_auto_pushd unset
    local _cd1_cd_succeeded=1
    # Save the current directory and the chpwd hook. They will be restored
    # by the exit trap in _cd1_in.
    local _cd1_chpwd_function=$functions[chpwd]
    # Save the current directory in $OLDPWD. _cd_in will call cd, which would
    # generally call cd
    local OLDPWD=$PWD
    # Turn off the chpwd hook function and the associated hook array.
    local chpwd_functions=
    unset -f chpwd 2>/dev/null
    # Call a separate function to do the work. Its exit trap will take care
    # of cleanup. The reason to have a separate function is so that the
    # local variables defined here can be used in the exit trap.
    _cd1_in
  else
    _dirs
  fi
}

_cd1 "$@"
1
27.01.2020, 22:16

Теги

Похожие вопросы