Skip to content

Commit

Permalink
✨ Add name
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Aug 26, 2023
1 parent f5a3e15 commit c607f5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/neomuttp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local ext = string.match(package.cpath, '([^.]+)[;|$]')
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext

local prompt = require "prompt"
prompt.name = 'texlua'
prompt.name = 'neomutt'
prompt.prompts = { '> ', '>> ' }
prompt.colorize = true
prompt.history = os.getenv('HOME') .. '/.lua_history'
Expand Down
20 changes: 15 additions & 5 deletions prompt-style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local string = require "string"
local table = require "table"
local lfs = require "lfs"
local ansicolors = require "ansicolors"
local prompt = require "prompt"
---@diagnostic disable: deprecated
if table.unpack == nil then table.unpack = unpack end

---get distribution
Expand Down Expand Up @@ -52,12 +54,17 @@ local function get_icon()
end

---get version
---@param name string
---@param logo string
---@param format string
---@return string
local function get_version(logo)
logo = logo or ""
local function get_version(name, logo, format)
name = name or prompt.name
logo = logo or ""
format = format or " %s "
name = string.format(format, name)
local version = string.gsub(_VERSION, ".*%s+", "")
return logo .. version
return logo .. name .. version
end

---get time
Expand All @@ -79,18 +86,21 @@ local function get_cwd()
end

---generate ps1.
-- `name` is for `get_version()`
-- `sections` is an array whose element is like `{ "white", "blue", get_cwd }`
-- and its order determine the order of prompt sections.
-- `sep` is separator. `char` is the last character like `> `
-- `format` determine the space and by default is ' %s '.
---@param name string
---@param sections {1: integer, 2: integar, 3: string | function(): string}[]
---@param sep string
---@param char string
---@param format string
---@return function(): string
local function generate_ps1(sections, sep, char, format)
local function generate_ps1(name, sections, sep, char, format)
name = name or prompt.name
sections = sections or {
{"black", "yellow", get_icon()}, {"blue", "black", get_version()},
{"black", "yellow", get_icon()}, {"blue", "black", get_version(name)},
{"white", "blue", get_cwd}, {"black", "white", get_time}
}
sep = sep or ""
Expand Down

0 comments on commit c607f5c

Please sign in to comment.