Deprecated "<selection>" in favor of a better system using symlinks
This commit is contained in:
parent
0597d77f3f
commit
2c44abc2c4
71
bb.c
71
bb.c
@ -30,7 +30,7 @@
|
|||||||
#define BB_NAME "bb"
|
#define BB_NAME "bb"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BB_VERSION "0.28.1"
|
#define BB_VERSION "0.29.0"
|
||||||
#define MAX_BINDINGS 1024
|
#define MAX_BINDINGS 1024
|
||||||
#define SCROLLOFF MIN(5, (winsize.ws_row-4)/2)
|
#define SCROLLOFF MIN(5, (winsize.ws_row-4)/2)
|
||||||
|
|
||||||
@ -456,18 +456,7 @@ static int populate_files(bb_t *bb, const char *path)
|
|||||||
|
|
||||||
char pbuf[PATH_MAX] = {0}, prev[PATH_MAX] = {0};
|
char pbuf[PATH_MAX] = {0}, prev[PATH_MAX] = {0};
|
||||||
strcpy(prev, bb->path);
|
strcpy(prev, bb->path);
|
||||||
if (path == NULL) {
|
if (path != NULL) {
|
||||||
pbuf[0] = '\0';
|
|
||||||
} else if (strcmp(path, "<selection>") == 0) {
|
|
||||||
strcpy(pbuf, path);
|
|
||||||
} else if (strcmp(path, "..") == 0 && strcmp(bb->path, "<selection>") == 0) {
|
|
||||||
if (!bb->prev_path[0]) return -1;
|
|
||||||
strcpy(pbuf, bb->prev_path);
|
|
||||||
if (chdir(pbuf)) {
|
|
||||||
warn("Could not cd to: \"%s\"", pbuf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!normalize_path(bb->path, path, pbuf))
|
if (!normalize_path(bb->path, path, pbuf))
|
||||||
warn("Could not normalize path: \"%s\"", path);
|
warn("Could not normalize path: \"%s\"", path);
|
||||||
if (pbuf[strlen(pbuf)-1] != '/')
|
if (pbuf[strlen(pbuf)-1] != '/')
|
||||||
@ -478,10 +467,8 @@ static int populate_files(bb_t *bb, const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(bb->path, "<selection>") != 0) {
|
strcpy(bb->prev_path, prev);
|
||||||
strcpy(bb->prev_path, prev);
|
setenv("BBPREVPATH", bb->prev_path, 1);
|
||||||
setenv("BBPREVPATH", bb->prev_path, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bb->dirty = 1;
|
bb->dirty = 1;
|
||||||
strcpy(bb->path, pbuf);
|
strcpy(bb->path, pbuf);
|
||||||
@ -505,33 +492,24 @@ static int populate_files(bb_t *bb, const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t space = 0;
|
size_t space = 0;
|
||||||
if (strcmp(bb->path, "<selection>") == 0) {
|
glob_t globbuf = {0};
|
||||||
for (entry_t *e = bb->selected; e; e = e->selected.next) {
|
char *pat, *tmpglob = memcheck(strdup(bb->globpats));
|
||||||
if ((size_t)bb->nfiles + 1 > space)
|
while ((pat = strsep(&tmpglob, " ")) != NULL)
|
||||||
bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*)));
|
glob(pat, GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);
|
||||||
e->index = bb->nfiles;
|
free(tmpglob);
|
||||||
bb->files[bb->nfiles++] = e;
|
for (size_t i = 0; i < globbuf.gl_pathc; i++) {
|
||||||
|
// Don't normalize path so we can get "." and ".."
|
||||||
|
entry_t *entry = load_entry(bb, globbuf.gl_pathv[i]);
|
||||||
|
if (!entry) {
|
||||||
|
warn("Failed to load entry: '%s'", globbuf.gl_pathv[i]);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
entry->index = bb->nfiles;
|
||||||
glob_t globbuf = {0};
|
if ((size_t)bb->nfiles + 1 > space)
|
||||||
char *pat, *tmpglob = memcheck(strdup(bb->globpats));
|
bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*)));
|
||||||
while ((pat = strsep(&tmpglob, " ")) != NULL)
|
bb->files[bb->nfiles++] = entry;
|
||||||
glob(pat, GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);
|
|
||||||
free(tmpglob);
|
|
||||||
for (size_t i = 0; i < globbuf.gl_pathc; i++) {
|
|
||||||
// Don't normalize path so we can get "." and ".."
|
|
||||||
entry_t *entry = load_entry(bb, globbuf.gl_pathv[i]);
|
|
||||||
if (!entry) {
|
|
||||||
warn("Failed to load entry: '%s'", globbuf.gl_pathv[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
entry->index = bb->nfiles;
|
|
||||||
if ((size_t)bb->nfiles + 1 > space)
|
|
||||||
bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*)));
|
|
||||||
bb->files[bb->nfiles++] = entry;
|
|
||||||
}
|
|
||||||
globfree(&globbuf);
|
|
||||||
}
|
}
|
||||||
|
globfree(&globbuf);
|
||||||
|
|
||||||
// RNG is seeded with a hash of all the inodes in the current dir
|
// RNG is seeded with a hash of all the inodes in the current dir
|
||||||
// This hash algorithm is based on Python's frozenset hashing
|
// This hash algorithm is based on Python's frozenset hashing
|
||||||
@ -699,16 +677,13 @@ static void run_bbcmd(bb_t *bb, const char *cmd)
|
|||||||
} else if (matches_cmd(cmd, "glob:")) { // +glob:
|
} else if (matches_cmd(cmd, "glob:")) { // +glob:
|
||||||
set_globs(bb, value[0] ? value : "*");
|
set_globs(bb, value[0] ? value : "*");
|
||||||
populate_files(bb, bb->path);
|
populate_files(bb, bb->path);
|
||||||
} else if (matches_cmd(cmd, "goto:")) { // +goto:
|
} else if (matches_cmd(cmd, "goto:") || matches_cmd(cmd, "goto")) { // +goto:
|
||||||
entry_t *e = load_entry(bb, value);
|
if (!value && !bb->selected) return;
|
||||||
|
entry_t *e = load_entry(bb, value ? value : bb->selected->fullname);
|
||||||
if (!e) {
|
if (!e) {
|
||||||
warn("Could not find file to go to: \"%s\"", value);
|
warn("Could not find file to go to: \"%s\"", value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IS_VIEWED(e)) {
|
|
||||||
set_cursor(bb, e->index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
char pbuf[PATH_MAX];
|
char pbuf[PATH_MAX];
|
||||||
strcpy(pbuf, e->fullname);
|
strcpy(pbuf, e->fullname);
|
||||||
char *lastslash = strrchr(pbuf, '/');
|
char *lastslash = strrchr(pbuf, '/');
|
||||||
|
@ -36,7 +36,8 @@ bbcmd move:-1
|
|||||||
bbcmd cd:..
|
bbcmd cd:..
|
||||||
|
|
||||||
## l,Right: Enter directory
|
## l,Right: Enter directory
|
||||||
if [ -d "$BB" ]; then bbcmd cd:"$BB"; fi
|
if [ -d "$BB" ]; then bbcmd cd:"$BB";
|
||||||
|
elif [ -L "$BB" ]; then bbcmd goto:"$(readlink -f "$BB")"; fi
|
||||||
|
|
||||||
## Ctrl-f: Search for file
|
## Ctrl-f: Search for file
|
||||||
file="$(find . -mindepth 1 -printf '%P\0' | bbpick "Find: ")"
|
file="$(find . -mindepth 1 -printf '%P\0' | bbpick "Find: ")"
|
||||||
@ -70,7 +71,7 @@ bbcmd cd:"$mark"
|
|||||||
[ "$BBPREVPATH" ] && bbcmd cd:"$BBPREVPATH"
|
[ "$BBPREVPATH" ] && bbcmd cd:"$BBPREVPATH"
|
||||||
|
|
||||||
## ;: Show selected files
|
## ;: Show selected files
|
||||||
bbcmd cd:'<selection>'
|
printf '%s\n' "$@" | less
|
||||||
|
|
||||||
## 0: Go to intitial directory
|
## 0: Go to intitial directory
|
||||||
bbcmd cd:"$BBINITIALPATH"
|
bbcmd cd:"$BBINITIALPATH"
|
||||||
@ -120,17 +121,21 @@ bbconfirm "Save the current settings? "
|
|||||||
echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh
|
echo "bbcmd glob:'$BBGLOB' sort:'$BBSORT' columns:'$BBCOLUMNS' $BBINTERLEAVE" > "$XDG_DATA_HOME"/bb/settings.sh
|
||||||
|
|
||||||
## Ctrl-s: Save the selection
|
## Ctrl-s: Save the selection
|
||||||
[ $# -gt 0 ]
|
|
||||||
savename="$(bbask "Save selection as: ")"
|
savename="$(bbask "Save selection as: ")"
|
||||||
savename="${savename%.sel}.sel"
|
savedir="$XDG_DATA_HOME/bb/${savename%.sel}.sel"
|
||||||
mkdir -p "$XDG_DATA_HOME"/bb
|
! [ -d "$savedir" ] || bbconfirm "Do you want to overwrite the existing save? "
|
||||||
printf '%s\0' "$@" > "$XDG_DATA_HOME/bb/$savename"
|
rm -rf "$savedir"
|
||||||
|
[ $# -gt 0 ] && mkdir -p "$savedir"
|
||||||
|
for f; do ln -sT "$f" "$savedir/${f##*/}" || exit 1; done
|
||||||
|
echo "Saved."
|
||||||
|
bbpause
|
||||||
|
|
||||||
## Ctrl-o: Open a saved selection
|
## Ctrl-o: Open a saved selection
|
||||||
[ -d "$XDG_DATA_HOME"/bb ]
|
[ -d "$XDG_DATA_HOME"/bb ]
|
||||||
[ $# -gt 0 ] && bbconfirm "The current selection will be discarded. "
|
[ $# -gt 0 ] && bbconfirm "The current selection will be discarded. "
|
||||||
loadpath="$(find "$XDG_DATA_HOME"/bb/ -mindepth 1 -name '*.sel' -printf '%P\0' | bbpick "Load selection: ")"
|
loadpath="$(find "$XDG_DATA_HOME"/bb/ -mindepth 1 -maxdepth 1 -name '*.sel' -printf '%P\0' | bbpick "Load selection: ")"
|
||||||
bbcmd deselect select: <"$XDG_DATA_HOME/bb/$loadpath"
|
find "$XDG_DATA_HOME/bb/$loadpath" -mindepth 1 -maxdepth 1 -printf '%l\0' | bbcmd deselect select:
|
||||||
|
bbcmd goto
|
||||||
|
|
||||||
## J: Spread selection down
|
## J: Spread selection down
|
||||||
bbcmd spread:+1
|
bbcmd spread:+1
|
||||||
|
Loading…
Reference in New Issue
Block a user