Compare commits

...

3 Commits

Author SHA1 Message Date
wash 907e0c1832 frontend: evaluate <config>/profile.bshell on startup 2026-06-15 17:41:41 +01:00
wash b8a5bd7338 frontend: update fx api usage 2026-06-15 17:41:26 +01:00
wash c68b1d2b26 runtime: update fx api usage 2026-06-15 17:41:08 +01:00
6 changed files with 40 additions and 17 deletions
+1 -1
View File
@@ -144,7 +144,7 @@ static enum bshell_status process_record(
} }
fx_string *record = fx_string_create_from_cstr( fx_string *record = fx_string_create_from_cstr(
fx_stringstream_ptr(cmd_p->cmd_tmp)); fx_stringstream_get_cstr(cmd_p->cmd_tmp));
bshell_pipeline_write_value( bshell_pipeline_write_value(
pipeline, pipeline,
FX_VALUE_OBJECT(record), FX_VALUE_OBJECT(record),
+1 -1
View File
@@ -347,7 +347,7 @@ enum bshell_status bshell_table_ctx_print_record(
} }
size_t to_write = fx_stringstream_get_length(strm); size_t to_write = fx_stringstream_get_length(strm);
const char *s = fx_stringstream_ptr(strm); const char *s = fx_stringstream_get_cstr(strm);
bool overflow = false; bool overflow = false;
if (to_write > c->col_width) { if (to_write > c->col_width) {
to_write = c->col_width - 2; to_write = c->col_width - 2;
+6 -9
View File
@@ -140,7 +140,7 @@ static bshell_command *resolve_native_command_local(
} }
bshell_command *result bshell_command *result
= bshell_native_command_create(fx_path_ptr(cmd_path)); = bshell_native_command_create(fx_path_get_cstr(cmd_path));
fx_path_unref(cmd_path); fx_path_unref(cmd_path);
return result; return result;
} }
@@ -171,19 +171,16 @@ static bshell_command *resolve_native_command(
fx_foreach(v, it) fx_foreach(v, it)
{ {
const char *tok = NULL; const char *tok = NULL;
fx_value_get_cstr(v, &tok);
fx_path *dir_path = fx_path_create_from_cstr(tok);
const fx_path *parts[] = {dir_path, cmd_name_path};
fx_path *full_path fx_path *full_path
= fx_path_join(parts, sizeof parts / sizeof parts[0]); = fx_path_join_list(2, v, &FX_VALUE_OBJECT(cmd_name));
fx_path_unref(dir_path);
if (!fx_path_is_file(full_path)) { if (!fx_path_is_file(full_path)) {
fx_path_unref(full_path); fx_path_unref(full_path);
continue; continue;
} }
result = bshell_native_command_create(fx_path_ptr(full_path)); result = bshell_native_command_create(
fx_path_get_cstr(full_path));
fx_path_unref(full_path); fx_path_unref(full_path);
break; break;
} }
@@ -254,8 +251,8 @@ static enum bshell_status process_args(struct bshell_cmdcall_p *cmdcall)
for (i32 i = cmdcall->cmd_args.count - 1; i >= 0; i--) { for (i32 i = cmdcall->cmd_args.count - 1; i >= 0; i--) {
fx_stringstream_reset(str); fx_stringstream_reset(str);
fx_value_to_string(&cmdcall->cmd_args.items[i], str, NULL); fx_value_to_string(&cmdcall->cmd_args.items[i], str, NULL);
fx_string *arg_str fx_string *arg_str = fx_string_create_from_cstr(
= fx_string_create_from_cstr(fx_stringstream_ptr(str)); fx_stringstream_get_cstr(str));
fx_array_push_back( fx_array_push_back(
cmdcall->cmd_args_processed, cmdcall->cmd_args_processed,
FX_VALUE_OBJECT(arg_str)); FX_VALUE_OBJECT(arg_str));
+2 -2
View File
@@ -220,7 +220,7 @@ static enum bshell_status eval_instruction(
fx_value_unset(&y); fx_value_unset(&y);
const fx_property *prop const fx_property *prop
= fx_type_get_property(ty, fx_stringstream_ptr(strm)); = fx_type_get_property(ty, fx_stringstream_get_cstr(strm));
fx_stringstream_unref(strm); fx_stringstream_unref(strm);
if (!prop) { if (!prop) {
@@ -267,7 +267,7 @@ static enum bshell_status eval_instruction(
fx_value_to_string(&x, strm, NULL); fx_value_to_string(&x, strm, NULL);
fx_string_prepend_cstr( fx_string_prepend_cstr(
result, result,
fx_stringstream_ptr(strm)); fx_stringstream_get_cstr(strm));
fx_value_unset(&x); fx_value_unset(&x);
arg--; arg--;
} }
+5 -4
View File
@@ -190,9 +190,10 @@ static fx_path *create_path(const char *dir_path, const char *script_path)
return paths[1]; return paths[1];
} }
fx_path *result = fx_path_join( fx_path *result = fx_path_join_list(
(const fx_path **)paths, 2,
sizeof paths / sizeof paths[0]); &FX_CSTR(dir_path),
&FX_CSTR(script_path));
fx_path_unref(paths[0]); fx_path_unref(paths[0]);
fx_path_unref(paths[1]); fx_path_unref(paths[1]);
@@ -210,7 +211,7 @@ enum bshell_status frontend_eval_file(
} }
struct bshell_file *file = NULL; struct bshell_file *file = NULL;
ctx->ctx_status = bshell_file_open(fx_path_ptr(path), &file); ctx->ctx_status = bshell_file_open(fx_path_get_cstr(path), &file);
fx_path_unref(path); fx_path_unref(path);
if (!FX_OK(ctx->ctx_status)) { if (!FX_OK(ctx->ctx_status)) {
+25
View File
@@ -9,6 +9,7 @@
#include <bshell/parse/token.h> #include <bshell/parse/token.h>
#include <bshell/verb.h> #include <bshell/verb.h>
#include <fx/cmdline/cmd.h> #include <fx/cmdline/cmd.h>
#include <fx/io/path.h>
#include <stdio.h> #include <stdio.h>
enum { enum {
@@ -83,6 +84,30 @@ static int bshell(
frontend_init(&ctx, flags); frontend_init(&ctx, flags);
enum bshell_status status = BSHELL_SUCCESS; enum bshell_status status = BSHELL_SUCCESS;
fx_path *config_base_dir = fx_path_get_system(FX_PATH_CONFIG);
fx_path *profile_path = fx_path_join_list(
3,
&FX_VALUE_OBJECT(config_base_dir),
&FX_CSTR("bshell"),
&FX_CSTR("profile.bshell"));
fx_path_unref(config_base_dir);
if (fx_path_is_file(profile_path)) {
status = frontend_eval_file(
&ctx,
NULL,
fx_path_get_cstr(profile_path));
if (status != BSHELL_SUCCESS) {
fprintf(stderr,
"%s: cannot evaluate '%s': %s\n",
exec_name,
fx_path_get_cstr(profile_path),
bshell_status_get_description(status));
}
}
fx_path_unref(profile_path);
size_t nr_input_files = fx_arglist_get_count( size_t nr_input_files = fx_arglist_get_count(
opt, opt,
FX_COMMAND_INVALID_ID, FX_COMMAND_INVALID_ID,