summaryrefslogtreecommitdiff
path: root/bin/raps2
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-02-18 22:31:56 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-02-18 22:31:56 +0100
commitcd0f94a5f22c0ac26f5ac458812cfd49e828d7ad (patch)
tree4797dfed3541a1bde381b154a40cbe9156ca9598 /bin/raps2
parentfa5a6a91dfb4cff3666bbb887a2d7db10af26ef2 (diff)
Improve XDG functions
Diffstat (limited to 'bin/raps2')
-rwxr-xr-xbin/raps244
1 files changed, 22 insertions, 22 deletions
diff --git a/bin/raps2 b/bin/raps2
index c33a033..42383b9 100755
--- a/bin/raps2
+++ b/bin/raps2
@@ -25,8 +25,8 @@ my ($action, @args) = @ARGV;
sub cmd_add {
my ($name) = @_;
- my $init = get_xdg_config_home() . '/init';
- my $store = get_xdg_data_home() . "/${name}";
+ my $init = get_xdg_config_file('init');
+ my $store = get_xdg_data_file($name);
my $pass;
if (-e $store) {
@@ -68,7 +68,7 @@ sub cmd_add {
sub cmd_dump {
my ($name) = @_;
- my $store = get_xdg_data_home() . "/${name}";
+ my $store = get_xdg_data_file($name);
my $password;
my $cipher;
@@ -93,7 +93,7 @@ sub cmd_dump {
sub cmd_get {
my ($name) = @_;
- my $store = get_xdg_data_home() . "/${name}";
+ my $store = get_xdg_data_file($name);
my $password;
my $cipher;
@@ -113,7 +113,7 @@ sub cmd_get {
sub cmd_info {
my ($name) = @_;
- my $store = get_xdg_data_home() . "/${name}";
+ my $store = get_xdg_data_file($name);
if (not -e $store) {
die("No such password\n");
@@ -131,8 +131,8 @@ sub cmd_info {
}
sub create_dot_dirs {
- make_path(get_xdg_config_home());
- make_path(get_xdg_data_home());
+ make_path(get_xdg_config_file());
+ make_path(get_xdg_data_file());
return;
}
@@ -165,7 +165,7 @@ sub create_pass {
sub get_password {
my $pass;
- my $passfile = get_xdg_config_home() . '/password';
+ my $passfile = get_xdg_config_file('password');
if (not -e $passfile) {
return create_pass($passfile);
@@ -187,26 +187,26 @@ sub get_password {
return $pass;
}
-sub get_xdg_config_home {
- my $env = $ENV{'XDG_CONFIG_HOME'};
- my $home = $ENV{'HOME'};
+sub get_xdg_config_file {
+ my ($file) = @_;
+ my $env = $ENV{'XDG_CONFIG_HOME'};
+ my $home = $ENV{'HOME'};
- if ($env) {
- return "${env}/raps2";
- }
+ $file //= q{};
+ $env //= "${home}/.config";
- return "${home}/.config/raps2";
+ return "${env}/raps2/${file}";
}
-sub get_xdg_data_home {
- my $env = $ENV{'XDG_DATA_HOME'};
- my $home = $ENV{'HOME'};
+sub get_xdg_data_file {
+ my ($file) = @_;
+ my $env = $ENV{'XDG_DATA_HOME'};
+ my $home = $ENV{'HOME'};
- if ($env) {
- return "${env}/raps2";
- }
+ $file //= q{};
+ $env //= "${home}/.local/share";
- return "${home}/.local/share/raps2";
+ return "${env}/raps2/${file}";
}
sub load_state_from {