From 2b1ad2b531a51529f52c3e7c5fa28cbfc3aa682f Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 1 Mar 2018 15:36:01 +0400 Subject: [PATCH] =?UTF-8?q?impl=C3=A9menter=20l'option=20-p=20avec=20edit?= =?UTF-8?q?=5Fcmd()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pff | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/pff b/pff index e4ec288..15fc54f 100755 --- a/pff +++ b/pff @@ -61,10 +61,35 @@ function __pfs_completion() { COMPREPLY=($(compgen -W "$(__pff_profiles)" "$cur")) } complete -F __pfs_completion -o bashdefault -o default pfs +function __pfe_completion() { + local cur prev opt comp + _get_comp_words_by_ref cur prev + if [[ "$prev" == -*p ]]; then + COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) + elif [ "$prev" == --profile ]; then + COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) + elif [[ "$cur" == -*p* ]]; then + comp="${cur#-*p}"; opt="${cur:0:$((${#cur}-${#comp}))}" + COMPREPLY=($(compgen -W "$(__pff_profiles "$opt")" -- "$cur")) + fi +} +complete -F __pfe_completion -o bashdefault -o default pfe function __pff_completion() { local cur prev opt comp _get_comp_words_by_ref cur prev - if [[ "$prev" == -*s ]]; then + if [ "${COMP_WORDS[1]}" == -e -o "${COMP_WORDS[1]}" == --edit ]; then + # ne compléter -p que si on est en mode --edit + if [[ "$prev" == -*p ]]; then + COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) + elif [ "$prev" == --profile ]; then + COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) + elif [[ "$cur" == -*p* ]]; then + comp="${cur#-*p}"; opt="${cur:0:$((${#cur}-${#comp}))}" + COMPREPLY=($(compgen -W "$(__pff_profiles "$opt")" -- "$cur")) + fi + elif [[ "$prev" == -*s ]]; then + COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) + elif [ "$prev" == --switch ]; then COMPREPLY=($(compgen -W "$(__pff_profiles)" -- "$cur")) elif [[ "$cur" == -*s* ]]; then comp="${cur#-*s}"; opt="${cur:0:$((${#cur}-${#comp}))}" @@ -207,6 +232,9 @@ supportées sont: et le fichier D du profil test. Si cette option est utilisée pour sélectionner un fichier dans un autre profil, le profil courant est restauré à la fin de la commande. + Attention: pour que l'option -p/--profile soit correctement reconnue + avec l'option -e/--edit, il faut que cette dernière option soit + mentionnée en premier sur la ligne de commande. -d, --diff [DESTP [WORKDIR]] -d, --diff [SRCP DESTP [WORKDIR]] @@ -820,7 +848,7 @@ function new_cmd() { # pff --patch function patch_cmd() { - local pffdir="$1" + local commit="$1" pffdir="$2" ensure_pffdir pffdir "$pffdir" } @@ -996,16 +1024,26 @@ function add_local_cmd() { # pff --edit function edit_cmd() { - local pffdir file rfile pfile Pfile - local profile r - local -a edits + local profile="$1"; shift + local pffdir file rfile pfile Pfile r + local -a edits args ensure_pffdir pffdir - setx profile=get_current_profile "$pffdir" - enote "Edition des fichiers dans le profil $profile" + [ -n "$profile" ] || setx profile=get_current_profile "$pffdir" + enote "Dans le profil $profile:" r=0 - for file in "$@"; do + while [ $# -gt 0 ]; do + if [[ "$1" == -* ]]; then + # nouvelle option + local prev_profile="$profile" + args=(+ -p:,--profile: profile=) + parse_args "$@"; set -- "${args[@]}" + [ "$profile" != "$prev_profile" ] && enote "Dans le profil $profile:" + continue + fi + file="$1"; shift + if [ -d "$file" ]; then ewarn "$file: est un répertoire. argument ignoré" continue @@ -1022,6 +1060,7 @@ function edit_cmd() { continue } setx Pfile=get_pfile "$pfile" "$profile" "$pffdir" + estep "Edition de $(ppath "$Pfile")" array_add edits "$Pfile" done @@ -1176,6 +1215,11 @@ done QUIET=1 # masquer les messages de git et rsync? VERYQUIET=1 # masquer les messages de git commit? +parse_mode= +if [ "$1" == -e -o "$1" == --edit ]; then + parse_mode=+ +fi + action=infos autopatch=1 version= @@ -1183,8 +1227,10 @@ disttype=auto ORIGEXTS=("${DEFAULT_ORIGEXTS[@]}") PROTECTS=("${DEFAULT_PROTECTS[@]}") unwrap=auto +commit=ask +profile= alternate= -args=( +args=($parse_mode --help '$exit_with display_help' -0,--init action=init --s:,--origext: '$add@ ORIGEXTS' @@ -1198,13 +1244,17 @@ args=( --auto-unwrap unwrap=auto --no-unwrap unwrap= -E,--unwrap unwrap=1 - -p,--patch action=patch + --patch action=patch + --ask-commit commit=ask + -c,--comit commit=1 + --no-commit commit= -a,--add-global action=add-global --locals action=list-locals --profiles action=list-profiles -s,--switch action=switch -b,--add-local action=add-local -e,--edit action=edit + -p:,--profile: profile= -d,--diff action=diff --infos action=infos -l,--list-names,--show-all alternate=1 @@ -1216,13 +1266,13 @@ array_fix_paths ORIGEXTS case "$action" in init) init_cmd "$@";; new) new_cmd "$autopatch" "$version" "$disttype" "$unwrap" "$@";; -patch) patch_cmd "$@";; +patch) patch_cmd "$commit" "$@";; add-global) add_global_cmd "$@";; list-locals) list_locals_cmd "$@";; list-profiles) list_profiles_cmd "$@";; switch) switch_cmd "$@";; add-local) add_local_cmd "$@";; -edit) edit_cmd "$@";; +edit) edit_cmd "$profile" "$@";; diff) diff_cmd "$alternate" "$@";; infos) infos_cmd "$alternate" "$@";; esac