aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-02-17 16:02:53 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-02-17 16:02:53 -0800
commitf9fc99d28e23a5930ca916cbe7abe13c718c6f58 (patch)
tree8a2211ecaeacf5ccfc17df807f9ed9e5cd54725d
parent2d9eac4237b23280fa9f10639bb74367f33729c6 (diff)
Added xwindow title setting, and $HOME -> ~ in the bb path area.
-rw-r--r--bb.c24
-rw-r--r--bb.h3
2 files changed, 25 insertions, 2 deletions
diff --git a/bb.c b/bb.c
index c525913..4470164 100644
--- a/bb.c
+++ b/bb.c
@@ -239,6 +239,7 @@ void handle_next_key_binding(bb_t *bb)
restore_term(&default_termios);
run_script(bb, binding->script);
init_term();
+ set_title(bb);
check_cmdfile(bb);
}
if (mouse_x != -1 && mouse_y != -1) {
@@ -430,6 +431,7 @@ int populate_files(bb_t *bb, const char *path)
dirty = 1;
strcpy(bb->path, pbuf);
+ set_title(bb);
// Clear old files (if any)
if (bb->files) {
@@ -637,6 +639,7 @@ void run_bbcmd(bb_t *bb, const char *cmd)
wait_for_process(&child);
signal(SIGTTOU, SIG_DFL);
init_term();
+ set_title(bb);
dirty = 1;
} else if (matches_cmd(cmd, "goto:")) { // +goto:
entry_t *e = load_entry(bb, value);
@@ -752,7 +755,14 @@ void render(bb_t *bb)
move_cursor(tty_out, 0, 0);
const char *color = TITLE_COLOR;
fputs(color, tty_out);
- fputs_escaped(tty_out, bb->path, color);
+
+ char *home = getenv("HOME");
+ if (home && strncmp(bb->path, home, strlen(home)) == 0) {
+ fputs("~", tty_out);
+ fputs_escaped(tty_out, bb->path + strlen(home), color);
+ } else {
+ fputs_escaped(tty_out, bb->path, color);
+ }
fputs(" \033[K\033[0m", tty_out);
static const char *help = "Press '?' to see key bindings ";
@@ -1099,6 +1109,18 @@ void set_sort(bb_t *bb, const char *sort)
}
/*
+ * Set the xwindow title property to: bb - current path
+ */
+void set_title(bb_t *bb)
+{
+ char *home = getenv("HOME");
+ if (home && strncmp(bb->path, home, strlen(home)) == 0)
+ fprintf(tty_out, "\033]2;bb: ~%s\007", bb->path + strlen(home));
+ else
+ fprintf(tty_out, "\033]2;bb: %s\007", bb->path);
+}
+
+/*
* If the given entry is not viewed or selected, remove it from the
* hash, free it, and return 1.
*/
diff --git a/bb.h b/bb.h
index 0d0fd85..a5e9536 100644
--- a/bb.h
+++ b/bb.h
@@ -25,7 +25,7 @@
#include "bterm.h"
// Macros:
-#define BB_VERSION "0.21.0"
+#define BB_VERSION "0.21.1"
#ifndef PATH_MAX
#define PATH_MAX 4096
@@ -220,6 +220,7 @@ static void set_cursor(bb_t *bb, int i);
static void set_selected(bb_t *bb, entry_t *e, int selected);
static void set_scroll(bb_t *bb, int i);
static void set_sort(bb_t *bb, const char *sort);
+static void set_title(bb_t *bb);
static void sort_files(bb_t *bb);
static char *trim(char *s);
static int try_free_entry(entry_t *e);