# -*-eselect-*- vim: ft=eselect # Copyright 2005-2012 Gentoo Foundation # Distributed under the terms of the GNU GPL version 2 or later inherit portage DESCRIPTION="Handle configuration file merges" MAINTAINER="eselect@gentoo.org" show_extra_help_text() { cat < 0 ]] ; then for target in ${targets[@]} ; do write_kv_list_entry "${target}" "" do_action config "${action}" "${target}" done else write_kv_list_entry "No out of date files found" fi } ### list action ### describe_list() { echo "List files which need merging" } do_list() { targets=( $(find_targets ) ) write_list_start "Configuration files needing action:" if [[ ${#targets[@]} > 0 ]] ; then write_numbered_list "${targets[@]}" else write_kv_list_entry "No out of date files found" fi } ### reject action ### describe_reject() { echo "Reject updates to the specified files" } do_reject() { generic_handle_one_file "reject" "reject_handler" "$@" } reject_handler() { rm --interactive "$@" } ### accept action ### describe_accept() { echo "Accept changes to the specified files" } do_accept() { generic_handle_one_file "accept" "accept_handler" "$@" } accept_handler() { local file for file in "$@" ; do local sfile="${file}" dfile="${file/._cfg????_}" echo "Replacing ${dfile} with ${sfile}..." mv --interactive "${sfile}" "${dfile}" done } ### reject-all action ### describe_reject-all() { echo "Reject all updates ($(highlight_warning dangerous))" } do_reject-all() { generic_handle_all "Rejecting" "reject" } ### accept-all action ### describe_accept-all() { echo "Accept all updates ($(highlight_warning dangerous))" } do_accept-all() { generic_handle_all "Accepting" "accept" } ### merge action ### describe_merge() { echo "Interactively merge changes to the specified files" } do_merge() { generic_handle_one_file "merge" "merge_handler" "$@" } merge_handler() { local file for file in "$@" ; do local sfile="${file}" dfile="${file/._cfg????_}" echo "Merging ${dfile} with ${sfile}..." merge_prog ${dfile} ${sfile} done } merge_prog() { if type vimdiff &>/dev/null ; then vimdiff "$@" else write_error_msg "Couldn't find a suitable merge program." write_error_msg "Currently I know how to use 'vimdiff', which you can" write_error_msg "get by installing app-editors/vim." die -q "No merge program found" fi } ### merge-all action ### describe_merge-all() { echo "Interactively merge all changes" } do_merge-all() { generic_handle_all "Merging" "merge" } ### display action ### describe_display() { echo "Display the proposed changes to the specified files" } do_display() { generic_handle_one_file "display" "display_handler" "$@" } display_handler() { local file for file in "$@" ; do local sfile="${file}" dfile="${file/._cfg????_}" echo "Proposed changes to ${dfile}:" diff_prog -u ${dfile} ${sfile} done } diff_prog() { if type colordiff &>/dev/null ; then colordiff "$@" else diff "$@" fi } ### display-all action ### describe_display-all() { echo "Display all proposed updates" } do_display-all() { generic_handle_all "Displaying" "display" } ### interactive action ### describe_interactive() { echo "Enter interactive mode" } do_interactive() { local targets command show_menu=yes show_list=yes config_protect_dirs 1>/dev/null while true ; do targets=( $(find_targets) ) # Are we finished? if [[ ${#targets[@]} == 0 ]] ; then write_list_start "Nothing left to do." break fi # Should we show a file list? if [[ -n ${show_list} ]] ; then show_list= write_list_start "Configuration files needing action:" write_numbered_list "${targets[@]}" echo fi # Should we show a menu? if [[ -n ${show_menu} ]] ; then show_menu= write_list_start "Enter command:" write_kv_list_entry "" "Work with the specified file" write_kv_list_entry "$(highlight d)isplay " "Display proposed change" write_kv_list_entry "$(highlight a)ccept " "Accept proposed change" write_kv_list_entry "$(highlight r)eject " "Reject proposed change" write_kv_list_entry "$(highlight m)erge " "Merge proposed change" echo write_kv_list_entry "accept-all" \ "Accept all changes ($(highlight_warning dangerous))" write_kv_list_entry "reject-all" \ "Reject all changes ($(highlight_warning dangerous))" echo write_kv_list_entry "$(highlight l)ist" "Show file list" write_kv_list_entry "$(highlight h)elp" "Show this menu again" write_kv_list_entry "$(highlight q)uit" "Exit the program" echo else write_list_start "Enter command ($(highlight h)elp to show menu)" fi echo -n "> " read command case ${command%%[[:space:]]*} in q|qu|qui|quit) break; ;; h|he|hel|help) show_menu=yes ;; l|li|lis|list) show_list=yes ;; d|di|dis|disp|displ|displa|display) local args=${command#*[[:space:]]} if [[ -z ${command//[^[:space:]]} ]] ; then write_error_msg "You didn't tell me which file to display" else do_action config display ${command#*[[:space:]]} fi ;; a|ac|acc|acce|accep|accept) local args=${command#*[[:space:]]} if [[ -z ${command//[^[:space:]]} ]] ; then write_error_msg "You didn't tell me which file to accept" else do_action config accept ${command#*[[:space:]]} fi show_list=yes ;; r|re|rej|reje|rejec|reject) local args=${command#*[[:space:]]} if [[ -z ${command//[^[:space:]]} ]] ; then write_error_msg "You didn't tell me which file to reject" else do_action config reject ${command#*[[:space:]]} fi show_list=yes ;; m|me|mer|merg|merge) local args=${command#*[[:space:]]} if [[ -z ${command//[^[:space:]]} ]] ; then write_error_msg "You didn't tell me which file to merge" else do_action config merge ${command#*[[:space:]]} fi show_list=yes ;; accept-all) do_action config accept-all show_list=yes ;; reject-all) do_action config reject-all show_list=yes ;; +([[:digit:]])*(+([[:space:]])+([[:digit:]]))) while true ; do local item ok= for item in ${command} ; do [[ -z ${targets[${item}-1]} ]] && continue [[ -z ${ok} ]] && write_list_start "Selected files:" ok=yes write_numbered_list_entry ${item} ${targets[${item}-1]} done if [[ -z ${ok} ]] ; then write_error_msg "Sorry, ${command} not valid" show_list=yes else echo write_list_start "Enter subcommand:" write_kv_list_entry "$(highlight d)isplay" "Display proposed change" write_kv_list_entry "$(highlight a)ccept" "Accept proposed change" write_kv_list_entry "$(highlight r)eject" "Reject proposed change" write_kv_list_entry "$(highlight m)erge" "Merge proposed change" write_kv_list_entry "$(highlight q)uit" "Return to parent menu" echo echo -n "> " read subcommand case ${subcommand} in q|qu|qui|quit) break; ;; d|di|dis|disp|displ|displa|display) do_action config display ${command} ;; a|ac|acc|acce|accep|accept) do_action config accept ${command} show_list=yes break ;; r|re|rej|reje|rejec|reject) do_action config reject ${command} show_list=yes break ;; m|me|mer|merg|merge) do_action config reject ${command} show_list=yes break ;; *) write_error_msg "Sorry, ${subcommand} not understood" ;; esac fi done ;; *) write_error_msg "Sorry, ${command} not understood" ;; esac done }