-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.pl
executable file
·66 lines (57 loc) · 1.6 KB
/
install.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
use warnings;
use strict;
# Get script path and home path
use Cwd qw(abs_path);
use constant PATH_ROOT => abs_path();
use constant PATH_HOME => $ENV{'HOME'};
# Flags for prompt
use constant PROMPT_NO => 'n';
use constant PROMPT_YES => 'y';
# ENV consts
use constant ENV_HOME => $ENV{HOME};
sub yesNoPrompt
{
my $inquery = shift;
my $defaultAnswer = shift || PROMPT_NO;
my $prompt
= $defaultAnswer eq PROMPT_NO
? '[' . PROMPT_YES . '/' . ( uc PROMPT_NO ) . ']'
: '[' . ( uc PROMPT_YES ) . '/' . PROMPT_NO . ']';
local $| = 1;
print "$inquery $prompt ";
chomp( my $answer = <STDIN> );
$answer = lc substr $answer, 0, 1 if $answer;
return !$answer ? $defaultAnswer eq PROMPT_YES : $answer eq PROMPT_YES;
}
my @fileConfigs = ( 'vimrc', 'bashrc', 'tmux.conf' );
foreach my $conf (@fileConfigs)
{
my $file = PATH_HOME . "/.$conf";
my $fileExists = -e $file;
if (!$fileExists
|| yesNoPrompt(
"Configuration file \`$file\` exists, overwrite with symlink?")
)
{
unlink $file;
symlink PATH_ROOT . "/$conf", $file;
print "Configuration symlink \`" . PATH_ROOT
. "/$conf\` => \`$file\` set.\n";
}
}
my @folders = ( '/.vim/backup', '/.vim/swap', '/.vim/undo' );
for my $folder (@folders)
{
$folder = ENV_HOME . $folder;
my $folderExists = -e $folder;
if (!$folderExists
&& yesNoPrompt(
"Folder \`$folder\` doesn't exist, create it?", PROMPT_YES
)
)
{
mkdir $folder;
print "Folder \`$folder\` created.\n";
}
}