lumesh 0.18.2

a lighting shell ⚡ bash alternative
Documentation
# #### config for interactive mode
if IS_INTERACTIVE {
    # ## ---appearance---
    let logo = '
    ⚡┓
      ┃ ┓┏┏┳┓┏┓
      ┗┛┗┻┛┗┗┗ '
    print logo.clr(rand.int(1,230)) 'lightweight'.clr(38) 'ultimate'.clr(48) 'modern'.clr(51) 'efficient'.clr(45)


    # ## welcome msg
    # set LUME_WELCOME= 'Welcome to Lumesh!'

    # ## prompt
    # template could be normal expression or func.
    # avaluable tmplate var: $CWD, $CWD_SHORT, $CFM_TAG, $STRICT_TAG, $STATUS, $DURATION, $JOBS
    # if template is lambda/func, it will be evaluated everytime.
    # avaluable fields in ctx: cfm,strict,status,duration,jobs
    set LUME_PROMPT_SETTINGS = {
        starship: false,
        lazy: 0,
        continuation: "... ",
        template: string.blue('$CWD_SHORT') + '|' + string.green('$CFM_TAG') + '|' + string.blue('$STRICT_TAG') + '❯  '.bold().yellow(),
    #   template: (dir,ctx) -> {
    #     string.blue($dir) + ' |'.green().bold() \
    #     + ($ctx.cfm ? 'CFM'.green() + '|' : '') \
    #     + ($ctx.strict ? 'S'.yellow() + '| ' : '' ) \
    #     + (if (fs.exists '.git') {git branch --show-current | .cyan()} else '') \
    #     + '> '.green().bold()
    # }
    }

    # ## base theme for syntax: 'one_dark', 'ayu_dark', 'light'
    LUME_THEME = 'ayu_dark'

    # ## syntax theme modify
    # LUME_THEME_CONFIG = {
    #    keyword: "\x1b[38;5;75m",
    #    operator: COLOR.violet,
    #    ...
    # }

    # LUME_EDITOR_THEME = {
    #     hint : "grey",
    #     completion_bg : "black",
    #     completion_fg : "dark_yellow",
    #     completion_selected_bg : "red",
    #     completion_selected_fg : "white"
    # }


    # ## ---interactive---

    # ## default strict mode
    # set LUME_STRICT = true
    # ## default cmd_frist_mode
    # set LUME_CFM = none

    # ## history file
    # set LUME_HISTORY_FILE = '~\AppData\lumesh\lume_histroy'

    # == completion
    # set LUME_COMPLETION_DIR = '~\AppData\lumesh\completions'
    set LUME_COMPLETION_CYCLE = true

    # ## report compute result type and values. default True.
    # set LUME_PRINT_DIRECT= False


    # ## sudo cmd for Alt+s
    # set LUME_SUDO_CMD = 'doas'

    # ## key bindings

    # ## key bindings
    # Key format: "MODIFIER_key" (order CTRL_ALT_SHIFT: e.g., "CTRL_ALT_k", "CTRL_q", "ALT_h")
    # Value type:
    #   String -> inserts text into current line
    #   lambda/function -> executes immediately with environment access
    #         fn receive one arg as current buffer.

    # ### cmdmark manage
    let save_cmdmark = (b) -> {if !$b {b = ui.text('mark cmd:')}; $b.trim()+"\n" >> '~/.cache/lumesh/cmdmark'; println "\t[MARKED]"}
    let select_cmdmark = (b) -> { fs.read ~/.cache/lumesh/cmdmark ?! | .lines() | ui.pick('select cmdmark:') }
    let save_dirmark = (b) -> if !fs.read(~/.cache/lumesh/dirmark).lines().contains(cwd()) ?: true { cwd()+"\n" >> '~/.cache/lumesh/dirmark'; println "\t[MARKED]"}
    let select_dirmark = (b) -> { fs.read ~/.cache/lumesh/dirmark ?! | .lines() | ui.pick('select dirmark:') | 'cd ' + _ }
    let timestamp = "'" + time.now().to_string('%Y-%m-%d %H:%M:%S') + "'"
    let fix_typos = (b) -> $b.replace('gerp', 'grep').replace('mroe', 'more').replace('les', 'less')

    # ### menu
    fn menu(b){
        let m = {
            save_cmdmark,
            select_cmdmark,
            save_dirmark,
            fix_typos
        }

        let ex = { ui.pick $m.keys() 'Fuzzy Execute' ?! | $m.at() }
        ex($b)
    } #?: e -> eprint e.msg

    # ## binding
    set LUME_HOT_BINDINGS = {
        CTRL_q: 'exit',
        ALT_m: save_cmdmark,
        CTRL_SHIFT_M: select_cmdmark,
        CTRL_SHIFT_D: select_dirmark,
        ALT_e: fix_typos,
        CTRL_SHIFT_t: timestamp,
        'CTRL_/': menu,
    }

    # ### functions for slash bindings
    let select_cmdmark = (b) -> { fs.read ~/.cache/lumesh/cmdmark ?! | .lines() | ui.pick('select cmdmark:') | eval_str() }
    let select_dirmark = (b) -> { fs.read ~/.cache/lumesh/dirmark ?! | .lines() | ui.pick('select dirmark:') | cd _ }
    let fuzzy_go = (b) -> {let base = $b ~: g'~|/' ? $b : './'; let max = $b == '/' ? 2 : 5; fd -t d --max-depth $max . $base | ui.pick('Fuzzy Go:') ?! | cd _}
    let open_file = (b) -> {fd -t file | ui.pick('select file:') ?! |start 'edit' _}
    let edit_file = (b) -> {let e = sys.has('EDITOR') ? $EDITOR : 'notepad'; fd -t file | ui.pick('edit file:') | $e _}
    let search_content = (b) -> {
        let t = len($b)>0 ? $b : ui.text 'search in filetype:' ?: 'all'
        ui.text 'search:' | rg -t $t --line-number --column --no-heading --smart-case --color=never -- _ | ui.pick 'select' ?! | .split(':') | .at(0) | start 'edit' _
    }
    let git_commit = (b) -> {
        git add -A;
        ui.text('commit message:') ?! | git commit -m _
    }

    # ## use `/key arg`to execute; `/hist`,`/history`,`/cds`,`/q` already builtin, never use these keys
    set LUME_SLASH_BINDINGS = {
        sm: save_cmdmark,
        sd: save_dirmark,
        m: select_cmdmark,
        d: select_dirmark,
        g: fuzzy_go,
        o: open_file,
        e: edit_file,
        sc: search_content,
        cm: git_commit,
    }

    # ## use `/` to execute menu
    # `/ query` for fuzzy jump already builtin
    fn LUME_SLASH_MENU(){
        let m = {
            save_cmdmark,
            save_dirmark,
            select_cmdmark,
            select_dirmark,
            fuzzy_go,
            open_file,
            edit_file,
            search_content,
            git_commit,
        }
        let ex = { ui.pick $m.keys() 'Fuzzy Execute' ?! | $m.at() }
        if ex {ex('')}
    } ?: e -> print e.msg


    # ## abbreviations

    set LUME_ABBREVIATIONS = {
        cpu: 'wmic cpu get name',
        sfc: 'sfc /scannow',
        net: 'netstat -ano',
        ip: 'ipconfig /all',
    }

    # ## alias
    alias int = into.int()
    alias str = into.string()
    alias each = list.map()
    alias sort = list.sort()
    alias group = list.group()
    alias table = into.table()
    alias format = string.format()
    alias join = list.join()
    alias fopen = fs.read()
    alias cat = fs.read()
    alias ls = fs.ls('-l')
    alias mkdir = fs.mkdir()
    alias touch = fs.write()
    alias mv = fs.mv()
    alias rm = fs.rm()
    alias cp = fs.cp()
    alias head = fs.head()
    alias tail = fs.tail()
    alias is_dir = fs.is_dir()
    alias is_file = fs.is_file()
    alias basename = fs.base_name()
    alias dirname = fs.dir_name()
    alias doc = explorer https://www.lumesh.cc.cd
    alias config = vi about.info().prelude

    # ## ---ai---
    # ## default AI Helper settings. following is default.
    let base = fs.dir_name($SCRIPT)
    let syntax = fs.read($base + '/syntax.md')
    set LUME_AI_CONFIG = {
    #     host: 'localhost:11434',
    #     api_key: '',
    #     model: '',
    #     chat_url: '/v1/chat/completions',
    #     complete_max_tokens: 10,
    #     chat_max_tokens: 100,
    #     hint_prompt: '',
    #     chat_prompt: '',
         syntax,
    }

    # ## ---update---
    fn update(){
        println 'checking latest version...'
        let url = 'https://codeberg.org/santo/lumesh/releases/latest'
        let ver = (curl -s $url ?: eprintln 'network err' && exit |  regex.find(r'\d[\d\.]+') )
        ver = ver[found]
        let latest = ($ver.split('.').join('').to_int() ?: 0)
        if $latest > 0 {
          let current = (about.version())
          current = $current.split('.').join('').to_int()
          if $latest > $current {
              print 'Found new version: ' $ver.green()
              if ui.confirm('download [normal edition for windows] now?') {
                  println 'download...'
                  fs.mkdir 'C:\Program Files(x86)\lumesh'
                  curl -o 'C:\Program Files(x86)\lumesh\lume' `https://codeberg.org/santo/lumesh/releases/download/v${ver}/lume-windows.exe`
              } else {
                  println 'you may download it manually:' $url
              }
          } else {
              println 'Already newest'.yellow()
          }
        } else {
          eprintln 'version check failed.'
        }
    }

}
# else {
# #### config for script mode
# }

# #### config for all mode
# IFS affect: 0:never; 2:cmd args; 4:for; 8:string.split; 16:csv; 32:pick; 62:all
set LUME_IFS_MODE=2
# set LUME_MODULES_PATH='~\AppData\Local\lumesh\mods'
# set LUME_MAX_SYNTAX_RECURSION = 100
# set LUME_MAX_RUNTIME_RECURSION = 800