// // DFM - Dylan's File Manager - Command Configuration file. // // Commands can be created using the FM_CMD macro which declares a function // that holds a struct fm_cmd and calls fm_cmd(). // // struct fm_cmd { // cut prompt; // Prompt text. // cut left; // Text left of cursor. // cut right; // Text right of cursor. // fm_key_press press; // Callback on press. // fm_key_enter enter; // Callback on enter. // u32 config; // Configuration. // }; // // The config field supports the following options: // // CMD_BG - Run the command in the background. // CMD_CONFLICT - Prompt on file conflicts. // CMD_MUT - Hint that the command might mutate directory entries. // CMD_EXEC - Skip the interactive prompt and execute the command. // CMD_MARK_DIR - Command must run in the mark directory. // CMD_NOT_MARK_DIR - Command must not run in the mark directory. // CMD_STDIN = Feed file under cursor to command via stdin. // CMD_FILE_CURSOR = Ignore marks and add the name under the cursor to input. // CMD_EXEC_MARK = Skip interactive prompt only if marks exist.. // CMD_EXEC_ROOT = Skip interactive prompt even if root. !! ## Shell cript can be embedded within dfm by using the embed command. ## The script will be run in $SHELL as the argument following '-c'. ## ## FM_CMD(cmd_bulk_rename, ## .prompt = CUT_NULL, ## .left = CUT($(embed script/bulk-rename)), ## .enter = fm_cmd_run_sh, ## .config = CMD_MARK_DIR | CMD_MUT | CMD_EXEC, ## ) ## ## Another useful example is embedding your opener script. ## ## FM_CMD(cmd_opener, ## .prompt = CUT_NULL, ## .left = CUT($(embed script/opener_ext)), ## .enter = fm_cmd_run_sh, ## .config = CMD_MARK_DIR | CMD_EXEC, ## ) ## ## Shell can also be typed directly but its cumbersone to add \\n to the end of ## each line and escape backslashes and double quotes. ## ## .left = CUT("echo \\"$@\\"\\n"), !! // If the FM_CMD system is too limiting you can define your own functions and // bind them to keys. The same function signature is used in navigation and // input modes. // // static void // my_custom_fn(struct fm *p) // { // // Go wild. // } // // Refer to dfm.c for more information. // FM_CMD(cmd_exec, .prompt = CUT(":"), .enter = fm_cmd_run, .config = CMD_MUT, ) FM_CMD(cmd_exec_sh, .prompt = CUT(":!"), .enter = fm_cmd_run_sh, .config = CMD_MUT | CMD_STDIN, ) FM_CMD(cmd_exec_stdin, .prompt = CUT(":<"), .enter = fm_cmd_run, .config = CMD_MUT | CMD_STDIN, ) FM_CMD(cmd_exec_open, .prompt = CUT(":"), .right = CUT(" %m"), .enter = fm_cmd_run, ) FM_CMD(cmd_exec_open_bg, .prompt = CUT(":"), .right = CUT(" %m &"), .enter = fm_cmd_run ) FM_CMD(cmd_link, .prompt = CUT(":"), .left = CUT("ln -sf %m %d"), .enter = fm_cmd_run, .config = CMD_NOT_MARK_DIR | CMD_MUT | CMD_EXEC_MARK | CMD_CONFLICT, ) FM_CMD(cmd_remove, .prompt = CUT(":"), .left = CUT("rm -rf %m"), .enter = fm_cmd_run, .config = CMD_MARK_DIR | CMD_MUT | CMD_EXEC_MARK, ) FM_CMD(cmd_copy, .prompt = CUT(":"), .left = CUT("cp -Rf %m %d"), .enter = fm_cmd_run, .config = CMD_NOT_MARK_DIR | CMD_MUT | CMD_EXEC_MARK | CMD_CONFLICT, ) FM_CMD(cmd_move, .prompt = CUT(":"), .left = CUT("mv -f %m %d"), .enter = fm_cmd_run, .config = CMD_NOT_MARK_DIR | CMD_MUT | CMD_EXEC_MARK | CMD_CONFLICT, ) FM_CMD(cmd_rename, .prompt = CUT(":"), .left = CUT("mv -f %f "), .enter = fm_cmd_run, .config = CMD_FILE_CURSOR | CMD_MUT, ) FM_CMD(cmd_chmod, .prompt = CUT(":"), .left = CUT("chmod"), .right = CUT(" %m"), .enter = fm_cmd_run, .config = CMD_MUT, ) FM_CMD(cmd_chown, .prompt = CUT(":"), .left = CUT("chown"), .right = CUT(" %m"), .enter = fm_cmd_run, .config = CMD_MUT, ) FM_CMD(cmd_copy_clipboard, .prompt = CUT(":"), .left = get_env("DFM_COPYER", DFM_COPYER), .enter = fm_cmd_run, .config = CMD_EXEC | CMD_STDIN, ) FM_CMD(cmd_cd, .prompt = CUT(":cd "), .enter = fm_cmd_cd, ) FM_CMD(cmd_touch, .prompt = CUT(":"), .left = CUT("touch "), .enter = fm_cmd_run, .config = CMD_MUT, ) FM_CMD(cmd_mkdir, .prompt = CUT(":"), .left = CUT("mkdir -p "), .enter = fm_cmd_run, .config = CMD_MUT, ) FM_CMD(cmd_trash, .prompt = CUT(":"), .left = get_env("DFM_TRASH", DFM_TRASH), .right = CUT(" %m"), .enter = fm_cmd_run, .config = CMD_MARK_DIR | CMD_MUT | CMD_EXEC_MARK, ) FM_CMD(cmd_bulk_rename, .prompt = CUT_NULL, .left = CUT($(embed script/bulk-rename)), .enter = fm_cmd_run_sh, .config = CMD_MARK_DIR | CMD_MUT | CMD_EXEC, ) FM_CMD(cmd_editor, .prompt = CUT_NULL, .left = CUT("kak %m"), .enter = fm_cmd_run, .config = CMD_MUT | CMD_EXEC, ) #define PBUFS 256 /* If you have paths longer than 256 chars I can't help you */ static void cmd_gd(struct fm *p) { char pbuf[PBUFS]; FILE *fzf = popen("fd -t d -u | fzf --algo=v1", "r"); fgets(pbuf, PBUFS, fzf); // Not sure why, but the -1 on strlen is required if (pbuf[0] == '/') fm_path_cd(p, pbuf, strlen(pbuf)-1); else fm_path_cd_relative(p, pbuf, strlen(pbuf)-1); pclose(fzf); } //FM_CMD(cmd_gd, // .prompt = CUT_NULL, // .left = CUT("fd -t d -u | fzf --algo=v1"), // .enter = fm_cmd_cd, // .config = CMD_MUT | CMD_EXEC, //)