ソースを参照

Support XDG_CONFIG_HOME

master
Arun Prakash Jana 5年前
コミット
80c35e85bd
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: A75979F35C080412
5個のファイルの変更46行の追加14行の削除
  1. +1
    -1
      scripts/quitcd/quitcd.bash
  2. +1
    -0
      scripts/quitcd/quitcd.csh
  3. +1
    -0
      scripts/quitcd/quitcd.fish
  4. +1
    -1
      scripts/quitcd/quitcd.zsh
  5. +42
    -12
      src/nnn.c

+ 1
- 1
scripts/quitcd/quitcd.bash ファイルの表示

@@ -2,7 +2,7 @@ n()
{ {
nnn "$@" nnn "$@"


NNN_TMPFILE=~/.config/nnn/.lastd NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd


if [ -f $NNN_TMPFILE ]; then if [ -f $NNN_TMPFILE ]; then
. $NNN_TMPFILE . $NNN_TMPFILE


+ 1
- 0
scripts/quitcd/quitcd.csh ファイルの表示

@@ -1,2 +1,3 @@
# NOTE: set NNN_TMPFILE correctly if you use 'XDG_CONFIG_HOME'
set NNN_TMPFILE=~/.config/nnn/.lastd set NNN_TMPFILE=~/.config/nnn/.lastd
alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"' alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"'

+ 1
- 0
scripts/quitcd/quitcd.fish ファイルの表示

@@ -5,6 +5,7 @@
function n --description 'support nnn quit and change directory' function n --description 'support nnn quit and change directory'
nnn $argv nnn $argv


# NOTE: set NNN_TMPFILE correctly if you use 'XDG_CONFIG_HOME'
set NNN_TMPFILE ~/.config/nnn/.lastd set NNN_TMPFILE ~/.config/nnn/.lastd


if test -e $NNN_TMPFILE if test -e $NNN_TMPFILE


+ 1
- 1
scripts/quitcd/quitcd.zsh ファイルの表示

@@ -2,7 +2,7 @@ n()
{ {
nnn "$@" nnn "$@"


NNN_TMPFILE=~/.config/nnn/.lastd NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd


if [ -f $NNN_TMPFILE ]; then if [ -f $NNN_TMPFILE ]; then
. $NNN_TMPFILE . $NNN_TMPFILE


+ 42
- 12
src/nnn.c ファイルの表示

@@ -4301,47 +4301,77 @@ static void usage(void)
static bool setup_config(void) static bool setup_config(void)
{ {
size_t r, len; size_t r, len;
char *xdgcfg = getenv("XDG_CONFIG_HOME");
bool xdg = FALSE;


/* Set up configuration file paths */ /* Set up configuration file paths */
len = strlen(home) + 1 + 20; /* add length of "/.config/nnn/plugins" */ if (xdgcfg && xdgcfg[0]) {
DPRINTF_S(xdgcfg);
if (xdgcfg[0] == '~') {
r = xstrlcpy(g_buf, home, PATH_MAX);
xstrlcpy(g_buf + r - 1, xdgcfg + 1, PATH_MAX);
xdgcfg = g_buf;
DPRINTF_S(xdgcfg);
}

if (!xdiraccess(xdgcfg)) {
xerror();
return FALSE;
}

len = strlen(xdgcfg) + 1 + 12; /* add length of "/nnn/plugins" */
xdg = TRUE;
}

if (!xdg)
len = strlen(home) + 1 + 20; /* add length of "/.config/nnn/plugins" */

cfgdir = (char *)malloc(len); cfgdir = (char *)malloc(len);
plugindir = (char *)malloc(len); plugindir = (char *)malloc(len);
if (!cfgdir || !plugindir) { if (!cfgdir || !plugindir) {
xerror(); xerror();
return FALSE; return FALSE;
} }
r = xstrlcpy(cfgdir, home, len);


/* Create ~/.config */ if (xdg) {
xstrlcpy(cfgdir + r - 1, "/.config", len - r); xstrlcpy(cfgdir, xdgcfg, len);
DPRINTF_S(cfgdir); r = len - 12;
if (!create_dir(cfgdir)) { } else {
xerror(); r = xstrlcpy(cfgdir, home, len);
return FALSE; /* Create ~/.config */
xstrlcpy(cfgdir + r - 1, "/.config", len - r);
DPRINTF_S(cfgdir);
if (!create_dir(cfgdir)) {
xerror();
return FALSE;
}

r += 8; /* length of "/.config" */
} }


/* Create ~/.config/nnn */ /* Create ~/.config/nnn */
xstrlcpy(cfgdir + r - 1, "/.config/nnn", len - r); xstrlcpy(cfgdir + r - 1, "/nnn", len - r);
DPRINTF_S(cfgdir); DPRINTF_S(cfgdir);
if (!create_dir(cfgdir)) { if (!create_dir(cfgdir)) {
xerror(); xerror();
return FALSE; return FALSE;
} }


xstrlcpy(cfgdir + r + 12 - 1, "/plugins", 9); /* Create ~/.config/nnn/plugins */
xstrlcpy(cfgdir + r + 4 - 1, "/plugins", 9);
DPRINTF_S(cfgdir); DPRINTF_S(cfgdir);


xstrlcpy(plugindir, cfgdir, len); xstrlcpy(plugindir, cfgdir, len);
DPRINTF_S(plugindir); DPRINTF_S(plugindir);


/* Create ~/.config/nnn/plugins */
if (!create_dir(cfgdir)) { if (!create_dir(cfgdir)) {
xerror(); xerror();
return FALSE; return FALSE;
} }


/* Reset to config path */ /* Reset to config path */
cfgdir[r + 11] = '\0'; cfgdir[r + 3] = '\0';
DPRINTF_S(cfgdir); DPRINTF_S(cfgdir);


/* Set selection file path */ /* Set selection file path */


||||||
x
 
000:0
読み込み中…
キャンセル
保存