diff --git a/src/_adr_move b/src/_adr_move new file mode 100755 index 0000000..87e66ec --- /dev/null +++ b/src/_adr_move @@ -0,0 +1,32 @@ +#!/bin/bash +set -e +eval "$($(dirname $0)/adr-config)" + +source=$("$adr_bin_dir/_adr_file" "${1:?SOURCE}") +source_dir=${source%/*} +source_filename=${source##*/} +target=${2:?TARGET} +target_num=$(printf "%04d" ${target}) +target_filename=${source_filename/[0-9][0-9][0-9][0-9]/${target_num}} + +source_title=$("$adr_bin_dir/_adr_title" "$source") +source_short_title=$(echo "${source_title}" | sed 's/^[0-9]\+//g') +# source_num=$(echo "${source_title}" | sed 's/\(^[0-9]\+\)\..*/\1/g') +target_title="${target}${source_short_title}" + +pattern_escape_cmd='sed -e s/[]\/$*.^[]/\\&/g' +sub_escape_cmd='sed -e s/[\/&]/\\&/g' +source_filename_escaped=$(echo "${source_filename}" | ${pattern_escape_cmd}) +target_filename_escaped=$(echo "${target_filename}" | ${sub_escape_cmd}) + +source_title_escaped=$(echo "${source_title}" | ${pattern_escape_cmd}) +target_title_escaped=$(echo "${target_title}" | ${sub_escape_cmd}) + +# update file +mv ${source} ${source_dir}/${target_filename} + +# update references (it will update $target_file as well) +for adr_filename in $("$adr_bin_dir/adr-list") +do + sed -i "s/${source_filename_escaped}/${target_filename_escaped}/g ; s/${source_title_escaped}/${target_title_escaped}/g" ${adr_filename} +done diff --git a/src/adr-move b/src/adr-move new file mode 100755 index 0000000..a89eae6 --- /dev/null +++ b/src/adr-move @@ -0,0 +1,20 @@ +#!/bin/bash +set -e +eval "$($(dirname $0)/adr-config)" + +## usage: adr link SOURCE LINK TARGET REVERSE-LINK +## +## Creates a link between two ADRs, from SOURCE to TARGET new. +## SOURCE and TARGET are both a reference (number or partial filename) to an ADR +## LINK is the description of the link created in the SOURCE. +## REVERSE-LINK is the description of the link created in the TARGET +## +## E.g. to create link ADR 12 to ADR 10 +## +## adr link 12 Amends 10 "Amended by" +## + +source="${1:?SOURCE}" +target="${2:?TARGET}" + +"$adr_bin_dir/_adr_move" "$source" "$target"