Skip to main content
added 1 character in body
Source Link
Toby Speight
  • 88.3k
  • 14
  • 104
  • 327
export sectnumlevels=2    
export toc="true"    
export includedir="include"

It's not clear why any of these need to be exported

[[ -z "$1" ]] && { echo "need a file" ; exit 1 ; }

Error messages should go to stderr, not stdout: echo >&2. And we could use portable shell [ instead of [[, rather than making the script Bash-specific.

  sed -i '1 i ---' "$file"
  sed -i "/^---/a title: $title" "$file"
  sed -i "/^title:/a author: $author" "$file"
  sed -i "/^author:/a date: $date" "$file"   
  sed -i "/^date:/a type: $type" "$file"     
  sed -i "/^type:/a draft: $draft" "$file"   
  sed -i "/^draft:/a categories: $categories" "$file"
  sed -i "/^categories:/a tags: $tags" "$file"
  sed -i '/^tags:/a ---' "$file"

It's inefficient to repeatedly open anand write $file. Replace all this with a single sed program that inserts all of the required lines before line 1.

export sectnumlevels=2    
export toc="true"    
export includedir="include"

It's not clear why any of these need to be exported

[[ -z "$1" ]] && { echo "need a file" ; exit 1 ; }

Error messages should go to stderr, not stdout: echo >&2. And we could use portable shell [ instead of [[, rather than making the script Bash-specific.

  sed -i '1 i ---' "$file"
  sed -i "/^---/a title: $title" "$file"
  sed -i "/^title:/a author: $author" "$file"
  sed -i "/^author:/a date: $date" "$file"   
  sed -i "/^date:/a type: $type" "$file"     
  sed -i "/^type:/a draft: $draft" "$file"   
  sed -i "/^draft:/a categories: $categories" "$file"
  sed -i "/^categories:/a tags: $tags" "$file"
  sed -i '/^tags:/a ---' "$file"

It's inefficient to repeatedly open an write $file. Replace all this with a single sed program that inserts all of the required lines before line 1.

export sectnumlevels=2    
export toc="true"    
export includedir="include"

It's not clear why any of these need to be exported

[[ -z "$1" ]] && { echo "need a file" ; exit 1 ; }

Error messages should go to stderr, not stdout: echo >&2. And we could use portable shell [ instead of [[, rather than making the script Bash-specific.

  sed -i '1 i ---' "$file"
  sed -i "/^---/a title: $title" "$file"
  sed -i "/^title:/a author: $author" "$file"
  sed -i "/^author:/a date: $date" "$file"   
  sed -i "/^date:/a type: $type" "$file"     
  sed -i "/^type:/a draft: $draft" "$file"   
  sed -i "/^draft:/a categories: $categories" "$file"
  sed -i "/^categories:/a tags: $tags" "$file"
  sed -i '/^tags:/a ---' "$file"

It's inefficient to repeatedly open and write $file. Replace all this with a single sed program that inserts all of the required lines before line 1.

Source Link
Toby Speight
  • 88.3k
  • 14
  • 104
  • 327

export sectnumlevels=2    
export toc="true"    
export includedir="include"

It's not clear why any of these need to be exported

[[ -z "$1" ]] && { echo "need a file" ; exit 1 ; }

Error messages should go to stderr, not stdout: echo >&2. And we could use portable shell [ instead of [[, rather than making the script Bash-specific.

  sed -i '1 i ---' "$file"
  sed -i "/^---/a title: $title" "$file"
  sed -i "/^title:/a author: $author" "$file"
  sed -i "/^author:/a date: $date" "$file"   
  sed -i "/^date:/a type: $type" "$file"     
  sed -i "/^type:/a draft: $draft" "$file"   
  sed -i "/^draft:/a categories: $categories" "$file"
  sed -i "/^categories:/a tags: $tags" "$file"
  sed -i '/^tags:/a ---' "$file"

It's inefficient to repeatedly open an write $file. Replace all this with a single sed program that inserts all of the required lines before line 1.