From 197d46631a333176c2f82b72cc8ca1c0e8bead82 Mon Sep 17 00:00:00 2001 From: PHO Date: Tue, 1 Oct 2013 13:18:44 +0900 Subject: [PATCH] tools/export.pl --- GNUmakefile | 20 +++++++++++++++++--- tools/export.pl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tools/export.pl diff --git a/GNUmakefile b/GNUmakefile index e38637d..dbfabae 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,12 +6,14 @@ help: @echo " make lint - lint The Sugar System." @echo " make update - update repository with the current dot files." @echo " make commit - commit changes to the repository." - @echo " make install - update the current dot files with the repository." + @echo " make install - update current dot files with the repository." @echo " make import FILES=" - @echo " - import the dot files into the repository." + @echo " - import dot files into the repository." @echo " make import-all" @echo " - import every uncontrolled dot files, which aren't" @echo " ignored, into the repository." + @echo " make export FILSE=" + @echo " - export dot files from the repository." @echo " make diff FILE=" @echo " - show diff of the dot file." @echo @@ -55,6 +57,18 @@ import-all: perl ./tools/import.pl -git status +ifeq ($(FILES),) +export: + @echo "Specify at least one file." + @echo "Usage: $(MAKE) export FILES=" + @exit 1 +else +export: + @echo $(FILES) | \ + tr -s " " "\n" | \ + perl ./tools/export.pl +endif + ifeq ($(FILE),) diff: @echo "Specify one file." @@ -65,4 +79,4 @@ diff: perl ./tools/diff.pl $(FILE) | $(PAGER) endif -.PHONY: help lint update commit install import diff +.PHONY: help lint update commit install import export diff diff --git a/tools/export.pl b/tools/export.pl new file mode 100644 index 0000000..46f50c0 --- /dev/null +++ b/tools/export.pl @@ -0,0 +1,39 @@ +use strict; +use warnings; +use Smart::Comments; +use lib 'tools'; +require 'utils.pl'; +use File::Spec; +use File::Compare; +use File::Copy; + +sub main { + while (defined(my $arg = <>)) { + chomp $arg; + + my $rel = File::Spec->file_name_is_absolute($arg) + ? File::Spec->abs2rel($arg, $ENV{HOME}) + : $arg; + my $abs = File::Spec->rel2abs($rel, $ENV{HOME}); + my $saved = rel2saved($rel); + + if (!-e $saved) { + print "SKIP: $rel is not in the repository.\n"; + next; + } + elsif (-e $abs) { + if (compare($abs, $saved) == 0) { + print "SKIP: $rel is identical to the copy in the repository.\n"; + } + else { + print "SKIP: $rel is different from the copy in the repository.\n"; + } + } + else { + print "Copying $saved to $abs...\n"; + copy($saved, $abs) or die $!; + } + } +} + +main(); -- 2.40.0