Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add move functionality #129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/_adr_move
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions src/adr-move
Original file line number Diff line number Diff line change
@@ -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"