Giter Site home page Giter Site logo

clink-flex-prompt's Introduction

Overview

Flex prompt is a flexible customizable prompt for Clink, and requires Clink v1.2.10 or higher.

There are several built-in prompt modules, and it's easy to add new custom prompt modules.
The style of the prompt can be customized in many ways as well.

Flex prompt for Clink was inspired by the zsh powerlevel10k theme by Roman Perepelitsa.
Some of the prompt modules are based on cmder-powerline-prompt.

clink-flex-prompt

Installation

Via .zip file

  1. Go to the Releases page.
  2. Download the latest clink-flex-prompt-*.zip file.
  3. Extract the files from it into your Clink scripts directory (use clink info to find it if you're not sure where it is).

Or, via Scoop

  1. Run scoop install clink-flex-prompt

Fonts

There is no "best" or "right" or "wrong" font. The most important thing is to pick a font whose shape you like.

Flex prompt's configuration wizard will ask few questions, and it's ok for some of the questions to look ugly -- choose the appropriate answer, and the wizard will adapt accordingly.

Flex prompt can use fancy characters, if you want, to personalize the prompt with shapes and icons. To use fancy characters, you'll need to find a font with Powerline characters and/or icon characters. The nerd fonts site has a large selection of special fonts. The configuration wizard lets you choose from the most common fancy characters, but you can also manually configure flex prompt (with Lua code) to use just about any special characters.

Benefits of fancy characters:

  • Your prompt will look fancy on the screen.

Drawbacks of fancy characters:

  • If you copy/paste from the screen to somewhere else, then fancy characters may not be readable by other people depending on what font they're using.
  • The same font may look different in different terminal programs, because of features or limitations in the terminal programs.
  • Some of the fancy characters require special fonts.

Here are some recommended fonts to consider:

  • Meslo Nerd Font patched by romkatv: this is a patched version of Meslo Nerd Font.
  • Cascadia Code: recent versions of this font include Powerline symbols, but the font doesn't include icon characters.
  • Caskaydia Cove Nerd Font: this is a patched version of Cascadia Code that adds many icon characters.
  • FiraCode Nerd Font: this is a patched version of Fira Code that adds Powerline symbols and many icon characters.
  • RobotoMono Nerd Font: this is a patched version of Roboto Mono that adds Powerline symbols and many icon characters.
  • And there are many other fonts to have fun with -- enjoy!

NOTE: Most Nerd Fonts have multiple variations of the font included. The flexprompt configure wizard asks questions to figure out which variation of Nerd Font you're using (if any).

  • Variations named "Nerd Font Mono" or "NF Mono" have small icons that take up only 1 cell (e.g. "RobotoMono Nerd Font Mono Medium").
  • Variations named just "Nerd Font" without "Mono" have larger double width icons that take up 2 cells (e.g. "RobotoMono Nerd Font Medium").

I installed a font; why won't it show up in the list of available terminal fonts?

The default built-in terminal window in Windows only lists a small set of predefined fonts. Other terminal hosts such as Windows Terminal or ConEmu make it easy to choose other fonts, without any extra steps.

If you want to add more fonts for the built-in terminal window, then you'll need to make some system registry changes. This article does a good job of collecting a variety of relevant info into one place. But if that link is broken when you're reading this, then you can do an internet search for "add fonts for console windows" or similar phrases.

Configuration Wizard

Flex prompt can be easily customized via its configuration wizard.

To start the wizard, run flexprompt configure and follow the instructions on the screen.

Advanced Configuration

The wizard doesn't cover everything, and more advanced configuration is possible by assigning settings manually in a flexprompt_config.lua file.

The script will look something like this:

flexprompt_config.lua

-- This pattern is in case this script runs before flexprompt.lua is loaded,
-- for example if they're in different directories.
flexprompt = flexprompt or {}
flexprompt.settings = flexprompt.settings or {}

-- Apply your settings here.
flexprompt.settings.style = "classic"
flexprompt.settings.heads = "pointed"
flexprompt.settings.lines = "two"
flexprompt.settings.left_prompt = "{battery}{cwd}{git}"
flexprompt.settings.right_prompt = "{exit}{overtype}{vpn}{duration}{time}"

Tip

By making your manual customizations modify settings (rather than replacing them), your customizations can adapt according to the options you've chosen in the flexprompt configuration wizard.

For example:

flexprompt.settings.left_prompt = flexprompt.settings.left_prompt:gsub("{git}", "{git:showremote}")
-- or
flexprompt.settings.left_prompt = flexprompt.settings.left_prompt .. "{my_custom_module}{python}"

Modules

The flexprompt.settings.left_prompt and flexprompt.settings.right_prompt string variables list prompt modules to be displayed.

  • "{admin}" shows whether the shell is running as administrator.
  • "{anyconnect}" shows the current Cisco AnyConnect VPN connection.
  • "{battery}" shows the battery level and whether the battery is charging.
  • "{break}" shows a break between two modules; is automatically discarded if adjacent to only one visible module.
  • "{conda}" shows the current Conda environment, if %CONDA_DEFAULT_ENV% is set.
  • "{cwd}" shows the current working directory.
  • "{duration}" shows the duration of the previous command, if more than 3 seconds.
  • "{env}" shows an environment variable.
  • "{exit}" shows the exit code of the previous command.
  • "{git}" shows git status.
  • "{hg}" shows Mercurial status.
  • "{histlabel}" shows the current %CLINK_HISTORY_LABEL%, if any.
  • "{keymap}" shows the current key bindings keymap (emacs mode, vi command mode, or vi insert mode).
  • "{k8s}" shows the current kubernetes context and namespace.
  • "{maven}" shows package info.
  • "{modmark}" shows a modified line indicator when the current line is a history entry and has been modified (only when the mark-modified-lines Readline config setting is on).
  • "{npm}" shows package name and version.
  • "{overtype}" shows indicator when overtype mode is on (i.e. when insert mode is off).
  • "{python}" shows the virtual environment.
  • "{scm}" shows source control management status (git, hg, svn, or custom SCM plugins).
  • "{svn}" shows Subversion status.
  • "{time}" shows the current time and/or date.
  • "{user}" shows the current user name and/or computer name.
  • "{vpn}" shows the current VPN or dialup connection.

Also, the following modules work together for a new "Bubbles" style, which is designed as a variation of the "lean" prompt style.

  • "{tbubble}" shows the top prompt line for the "Bubbles" style. You can add other modules in your top_prompt as well, even when using {tbubble}.
  • "{lbubble}" shows the left prompt for the "Bubbles" style. You can add other modules in your left_prompt as well, but they'll look best if they come after {lbubble}.
  • "{rbubble}" shows the right prompt for the "Bubbles" style. You can add other modules in your right_prompt as well, but they'll look best if they come before {rbubble}.
flexprompt.settings.left_prompt = "{battery}{user}{cwd}{git}"
flexprompt.settings.right_prompt = "{exit}{duration}{time}"

Configuring Options for Modules

Tip

You can search for "MODULE:" in flexprompt_modules.lua to find the available options for each module (including colors).

Some examples:

flexprompt.settings.left_prompt = "{battery:onlyicon}{user:type=computer}{cwd:color=magenta:type=folder}{git:nountracked:staged=blue}"
flexprompt.settings.right_prompt = "{exit:always}{duration:format=colons:tenths}{time:format=%a %h %e %R}"
  • TBD: details about configuring the modules.

Style

  • "lean" shows prompt modules using only colored text.
  • "classic" shows prompt modules using colored text on a gray background.
  • "rainbow" shows prompt modules using text on colored backgrounds.
flexprompt.settings.style = "classic"

Note: The flexprompt configure wizard lets you choose a "Bubbles" style. The "Bubbles" style is designed for use with flexprompt.settings.style = "lean"; there is not a separate "bubbles" style.

Charset

  • "ascii" uses only ASCII characters, and is compatible with all fonts; text copy/pasted from the terminal display will look right everywhere.
  • "unicode" uses Unicode characters to add styling to the prompt, and requires fonts compatible with powerline symbols; text copy/pasted from the terminal display will look wrong when pasted somewhere that doesn't use a compatible font.
flexprompt.settings.charset = "unicode"

Frame Color

  • "lightest"
  • "light"
  • "dark"
  • "darkest"
  • Custom frame colors can be provided as { frame_color, background_color, fluent_text_color, separator_color }. The fields can be color name strings or ANSI escape code SGR arguments (e.g. "31" is red text).

These choose the prompt background color for the "classic" style, and choose the frame and connection color for all styles.

-- Use a predefined set of coordinated dark colors:
flexprompt.settings.frame_color = "dark"

-- Or use custom colors:
flexprompt.settings.frame_color =
{
    "38;5;242",     -- frame color (gray 44%)
    "38;5;238",     -- background color (gray 28%)
    "38;5;246",     -- text color (gray 60%)
    "38;5;234",     -- separator color (gray 12%)
}

Separators

For the "classic" style:

  • "none" is just a space between prompt modules.
  • "vertical" is a vertical bar.
  • "pointed" is a sideward-pointing triangle (requires Unicode).
  • "slant" is slanted from bottom left to top right.
  • "backslant" is slanted from top left to bottom right.
  • "round" is a semi circle (requires Unicode).
  • "dot" is a dot (requires Unicode).
  • "updiagonal" is a small slash from bottom left to top right (requires Unicode).
  • "downdiagonal" is a small slash from top left to bottom right (requires Unicode).
  • (See flexprompt.lua for the most up to date list.)
  • Custom separators can be provided as a table with two values, for the left and right separators.

For the "rainbow" style:

  • Any of the Heads or Tails options may be used as separators.

For all styles:

  • "connector" shows a frame connector (see the Connection section further below).
-- Use a predefined separator:
flexprompt.settings.separator = "pointed"

-- Or use a custom separator:
flexprompt.settings.separator = { "»", "«" }

Tails and Heads

Tails are at the outside ends of the prompts. Heads are at the inside ends.

  • "flat" is a flat vertical edge.
  • "pointed" is a sideward-pointing triangle (requires Unicode).
  • "slant" is slanted from bottom left to top right (requires Unicode).
  • "backslant" is slanted from top left to bottom right (requires Unicode).
  • "round" is a semi circle (requires Unicode).
  • "blurred" uses shaded block characters to fade the edge (requires Unicode).
  • Custom end types can be provided as { open_string, close_string }. However, that is advanced usage and you need to know how background and foreground colors work; that isn't covered in this documentation.
flexprompt.settings.tails = "flat"
flexprompt.settings.heads = "blurred"

Lines

  • "one" uses a single line. Any right-side prompt modules are shown if there is room, and if the input text hasn't reached them.
  • "two" uses two lines. The first line shows the prompt modules, and the second line is for input text.
flexprompt.settings.lines = "two"

Connection

Only when using "both" sides:

  • "disconnected" shows blank space between the left and right side prompts.
  • "dotted" shows dots between the left and right side prompts.
  • "solid" draws a horizontal line connecting the left and right side prompts.
  • "dashed" draws a horizontal line using minus signs to connect the left and right side prompts.
  • A custom connection can be provided as a string.
-- Use a predefined connection:
flexprompt.settings.connection = "solid"

-- Or use a custom connection:
flexprompt.settings.connection = ""

Frame

When using "two" lines, left and right prompt frames can each be:

  • "none" shows no frame.
  • "square" shows a frame with square corners.
  • "round" shows a frame with rounded corners.
  • Custom frames can be provided as { top_frame, bottom_frame }.
-- Use predefined frame shapes:
flexprompt.settings.left_frame = "none"
flexprompt.settings.right_frame = "round"

-- Or use custom frame shapes:
flexprompt.settings.left_frame = { "╔═", "╚═" }
flexprompt.settings.right_frame = { "═╗", "◄───╜" }

Spacing

  • "compact" removes blank lines before the prompt.
  • "normal" neither removes nor adds blank lines before the prompt.
  • "sparse" removes blank lines before the prompt, and then inserts one blank line.
flexprompt.settings.spacing = "sparse"

Note: Clink v1.6.1 and higher have built-in support for a prompt.spacing setting, so flexprompt.settings.spacing is deprecated and ignored now. The flexprompt configure wizard will also automatically set Clink's prompt.spacing setting appropriately now.

Flow

  • "concise" shows minimal text for each prompt module.
  • "fluent" shows additional text for some prompt modules, to make the prompt "read" nicely.
flexprompt.settings.flow = "fluent"

Top Line

You can add an optional top line, above the left/right prompt text.

flexprompt.settings.top_prompt = "{histlabel}{user}"
flexprompt.settings.left_prompt = "{battery}{cwd}{git}{k8s}{npm}"
flexprompt.settings.right_prompt = "{exit}{duration}{time}"

The top line can optionally use a different style, as well.

flexprompt.settings.top_style = "lean"
flexprompt.settings.top_prompt = "{histlabel}{user}"
flexprompt.settings.style = "rainbow"
flexprompt.settings.left_prompt = "{battery}{cwd}{git}{k8s}{npm}"
flexprompt.settings.right_prompt = "{exit}{duration}{time}"

Note: If the top prompt uses a different style and a module appears in both the top prompt and the left or right prompts, then the module's colors in the top prompt will be used for the module in the left or right prompt. This happens because flexprompt only runs module's render function once, for efficiency, and the render function specifies the colors to use. It's very unusual for a module to show up more than once, so generally it shouldn't be a problem.

On Commands

You can make certain modules only show up when certain commands are typed.

For example, you might want the {k8s} Kubernetes module to only show up when you type kubectlSpace.

flexprompt.settings.oncommands = "moduleA=command1,moduleA=command2,moduleB=command1,moduleB=command3"
-- moduleA will only show up when "command1" or "command2" are typed.
-- moduleB will only show up when "command1" or "command3" are typed.

Miscellaneous Settings

-- Use all available icons:
flexprompt.settings.use_icons = true
-- Use icons only for the time and exit modules, and specifically disable icons for git:
-- This can be set in 2 ways, you can use ["key"] = true notation or key = true (no quotes)
flexprompt.settings.use_icons = { time_module = true, ["exit_module"] = true, git = false }

-- Enables battery level refresh in prompt:
flexprompt.settings.battery_idle_refresh = 30 -- every 30 seconds

-- Replaces %HOME% with ~ in the cwd module.
flexprompt.settings.use_home_tilde = true
-- Use additional symbol in cwd module in a git repo, when cwd type is 'smart' or 'rootsmart':
flexprompt.settings.symbols.cwd_git_symbol

-- Use custom prompt symbol (instead of >):
flexprompt.settings.symbols.prompt = "$"
-- Use custom prompt color (supersedes exit_zero_color and exit_nonzero_color):
flexprompt.settings.prompt_symbol_color = "magenta"
-- Use custom prompt symbol when overtype mode is on (i.e. insert mode is off):
flexprompt.settings.symbols.overtype_prompt = "#"
-- Use custom prompt symbol for the transient prompt:
flexprompt.settings.symbols.transient_prompt = ")"
-- Use custom prompt color when last exit code is zero:
flexprompt.settings.exit_zero_color = "brightgreen"
-- Use custom prompt color when last exit code is non-zero:
flexprompt.settings.exit_nonzero_color = "brightred"

-- Override a symbol that isn't in the font being used:
flexprompt.settings.symbol.charging = "++"

-- Override separators when style is 'lean':
flexprompt.settings.lean_separators = "   "

-- Run `git fetch` in a repo up to once every 60 minutes:
flexprompt.settings.git_fetch_interval = 60

-- Don't show duration unless a command takes at least this many seconds:
flexprompt.settings.duration_threshold = 10

-- Provide default arguments for a module:
flexprompt.defaultargs["module_name"] = "color=magenta"

-- Provide default arguments for a module, for a specific style (lean, classic, or rainbow):
flexprompt.defaultargs["module_name|rainbow"] = "color=blue,brightcyan"

-- Force flexprompt to tell git to take optional locks (not recommended):
flexprompt.settings.take_optional_locks = true

-- Disable detection of unpublished branches:
flexprompt.settings.dont_check_unpublished = true

-- Nerd Fonts version:  (e.g. NF version 3.0.0 and higher rearranged the icons)
flexprompt.settings.nerdfonts_version = 3
-- Nerd Fonts width:  (set to 1 to indicate font has mono width icons, or 2 to indicate double-width icons)
flexprompt.settings.nerdfonts_width = 2

-- Override certain icons with color emoji in Windows Terminal:
flexprompt.settings.use_color_emoji = true

-- Use Powerline icons (the font must support them):
flexprompt.settings.powerline_font = true

-- Supersede other settings and try to avoid displaying graphics that may not exist in all fonts.
flexprompt.settings.no_graphics = true

Writing Custom Prompt Modules

You can write prompt modules in Lua.

A prompt module can return a text string and a color for the text -- this adds a "segment" to the prompt. It can optionally return multiple pairs of text and colors to add multiple segments to the prompt. Or it can return nil to add no segments.

Put your prompt module code in a Lua file whose name starts with flexprompt_ in the same directory as the flexprompt.lua file.

Tip

Since scripts are loaded in alphabetical order, the easiest thing to do is name your script something that follows after flexprompt_ alphabetically. But another more advanced option is to defer making use of flexprompt. until the first onbeginedit event, and then the script name wouldn't have the alphabetical order limitation.

Here is a basic example of a prompt module, which we'll call "mfm" as an abbreviation for "my first module":

-- This is the prompt module function.
local function my_first_module(args)
    -- It returns some text to show in the prompt, and a color for the text.
    -- (The args will be explained in the next section.)
    return "Hello World", "magenta"
end

-- This registers the prompt module function with flexprompt.
-- Pass a string, and a function.
-- In your prompt, refer to the prompt module by putting its name inside
-- squiggly braces, such as "{mfm}" in this example.
flexprompt.add_module("mfm", my_first_module)

With the above code installed, if you set your flexprompt.left_prompt string to include "{mfm}" then your prompt will include a magenta segment that says "Hello World".

Options

Prompt modules can accept arguments to customize them. There are two flexprompt API functions to help with that.

If a module name is followed by a colon : then everything between the colon and the closing brace } is passed to the prompt module function as a string.

Let's suppose your prompt string includes "{mfm:excited:capitalize=upper}" and look at how the my_first_module example could use the arguments.

The excited part does not have an equal = sign, so it is a keyword. Your module function can use flexprompt.parse_arg_keyword() to check whether a specific keyword is present.

The case=upper part includes an equal = sign, so it is a token. Your module function can use flexprompt.parse_arg_token() to retrieve the part following the equal = sign.

Here is the example prompt module function, updated to recognize the two example arguments described above.

-- The MFM module:
--
-- This module replaces "{mfm}" in your prompt string with "Hello World".
--
-- This module accepts two arguments.  To use an argument, append a colon and
-- the argument after the module name:
--      excited             Adds an exclamation mark to the prompt text.
--      case=type           Applies capitalization according to 'type':
--                          - 'upper' applies upper case.
--                          - 'lower' applies lower case.

-- This is the prompt module function.
local function my_first_module(args)
    -- The text to show normally.
    local text = "Hello World"

    -- Check for the 'excited' argument keyword.  If present, then let's add
    -- exclamation marks to the text to express excitement.
    local excited = flexprompt.parse_arg_keyword(args, "excited")
    if excited then
        text = text .. "!!!"
    end

    -- Check for the 'case' argument token.  If present, then apply upper or
    -- lower casing, depending on the value of the 'case' token.
    local case = flexprompt.parse_arg_token(args, "case")
    if case == "upper" then
        text = string.upper(text)
    elseif case == "lower" then
        text = string.lower(text)
    end

    -- Return the final version of the text, and the color for the prompt
    -- module's segment in the prompt string.
    return text, "magenta"
end

-- This registers the prompt module function with flexprompt.
flexprompt.add_module("mfm", my_first_module)

Colors

Flexprompt can apply colors to prompt modules' segments. Each prompt module controls its own colors. But prompt modules may accepts arguments to allow customizing their colors.

If a module will only apply one color, then its token name may be color. But if the module has more than one color, or if you think it ever might have more than one color, then give each color a separate name (e.g. clean and dirty and "{mfm:clean=green:dirty=yellow}").

Your module function can use flexprompt.parse_colors() to retrieve the specified colors.

Here is where styling comes up for the first time: Each prompt segment actually has three things: text string, main color, and alternate color. In the "lean" and "classic" prompt styles, the main color says what text color to use (the alternate color is not used). But in the "rainbow" style the main color says what background color to use, and the alternate color says what text color to use. If the alternate color is omitted, then "white" is assumed. Overriding the alternate color may be desirable sometimes, for example to improve contrast.

Now we'll update the example prompt module to have a customizable color:

-- The MFM module:
--
-- This module replaces "{mfm}" in your prompt string with "Hello World".
--
-- This module accepts two arguments.  To use an argument, append a colon and
-- the argument after the module name:
--      excited             Adds an exclamation mark to the prompt text.
--      case=type           Applies capitalization according to 'type':
--                          - 'upper' applies upper case.
--                          - 'lower' applies lower case.
--      color=main,alt      Customize the default color.

-- This is the prompt module function.
local function my_first_module(args)
    -- The text to show normally.
    local text = "Hello World"

    -- Check for the 'excited' argument keyword.  If present, then let's add
    -- exclamation marks to the text to express excitement.
    local excited = flexprompt.parse_arg_keyword(args, "excited")
    if excited then
        text = text .. "!!!"
    end

    -- Check for the 'case' argument token.  If present, then apply upper or
    -- lower casing, depending on the value of the 'case' token.
    local case = flexprompt.parse_arg_token(args, "case")
    if case == "upper" then
        text = string.upper(text)
    elseif case == "lower" then
        text = string.lower(text)
    end

    -- Set up the default colors, and then parse a 'color' token to override the
    -- defaults with customized colors.
    local color = "magenta"
    local altcolor = "black"
    local color_arg = flexprompt.parse_arg_token(args, "color")
    color, altcolor = flexprompt.parse_colors(color_arg, color, altcolor)

    -- Return the final version of the text, and the color for the prompt
    -- module's segment in the prompt string.
    return text, color, altcolor
end

-- This registers the prompt module function with flexprompt.
flexprompt.add_module("mfm", my_first_module)

Abbreviation When Too Wide

Prompt modules can optionally return a callback function for use in case the terminal is not wide enough for the full prompt to be displayed. If the prompt is too wide, flexprompt calls each module's callback function to get an abbreviated form of the module and uses that instead to help the prompt fit.

To provide a callback function, the prompt module should return a table with a condense_callback field:

return {
    -- Normal results; text and colors.
    "full module text here",
    "green",
    "black",
    -- Callback when short form is needed.
    condense_callback = function ()
        return {
            "mini text",
            "green",
            "black",
        }
    end
}

Async Prompt Filtering

Clink supports asynchronous prompt filtering, where the input line editor stays responsive even while a prompt filter runs an operation that takes a long time to complete (for example git status in a large repo).

It's easy to make your custom modules take advantage of async prompt filtering.

Step 1 -- Collect info to be shown in the prompt

Make a function that collects the info that should appear in the prompt. Make the function return a table containing the info.

-- This function uses async prompt filtering to count the number of files in the
-- current directory.
local function collect_files_info()
    local num = 0

    -- Run the `dir` command.
    local f = io.popen("dir /b /a-d *")
    if f then
        for line in f:lines() do
            num = num + 1
        end
        f:close()
    end

    -- Return the collected info in a table.
    return {
        count = num
    }
end

Step Two -- Make it collect the info asynchronously

Make a module that calls flexprompt.prompt_info(). We'll discuss the middle two parameters later -- they can be empty strings if you don't need them.

local files_data = {}

local function files_module(args)
    -- Use async prompt filtering to call the collect_files_info() function.
    local info = flexprompt.prompt_info(files_data, "", "", collect_files_info)

    -- Build the prompt text.
    local text
    if info.count then
        text = flexprompt.append_text(info.count, flexprompt.make_fluent_text("file(s)"))
    else
        -- When the count isn't known, we can say that it's counting.
        text = flexprompt.make_fluent_text("(counting files)")
    end

    return text, "cyan"
end

flexprompt.add_module("files", files_module)

Step Three -- [Optional] Maybe reset the cached prompt info

Async prompt filtering shows the previous prompt content until the async collection function finishes.

But sometimes you may know in advance that the previous prompt content is no longer relevant. There is a simple way to automatically discard the previous cached prompt content.

The flexprompt.prompt_info() function takes two parameters which, if either is different from the previous prompt, will automatically reset the cached prompt content.

For example, the {git} module passes the git repo root directory and the current git branch. This is so that if you cd to a different repo or git switch to a different branch, the prompt doesn't mislead by showing info from a different repo or branch.

So, since this sample {files} module counts the files in the current directory, it makes sense to use the current directory for one of those two parameters:

local function files_module(args)
    -- Use async prompt filtering to call the collect_foo_info() function.
    -- Passing os.getcwd() makes the cached prompt info reset upon changing to
    -- a different current directory, so it doesn't (briefly) show a count from
    -- the previous prompt.
    local info = flexprompt.prompt_info(files_data, os.getcwd(), "", collect_files_info)

    -- Build the prompt text.
    local text
    if info.count then
        text = flexprompt.append_text(info.count, flexprompt.make_fluent_text("file(s)"))
    else
        -- When the count isn't known, we can say that it's counting.
        text = flexprompt.make_fluent_text("(counting files)")
    end

    return text, "cyan"
end

Customizable Styling

Tip

There is a lot of styling available, but it's poorly documented, sorry. You can reverse engineer details from reading flexprompt.lua and the configuration option tables near the beginning of it.

  • TBD: add more documentation about available styling.

Customizing Icons

Note

For now this section just has a quick example showing the structure for icon definitions in flexprompt.

  • TBD: add more documentation about customizing icons.
flexprompt.settings.symbol["icon_name_here"] =
{
    -- All fields here are optional; supply as many or as few as you want.

    -- Symbol to use in Windows Terminal, if flexprompt.settings.use_color_emoji is true.
    coloremoji      = "E",

    -- Symbol to use in Windows Terminal.
    winterminal     = "W",

    -- Symbol to use in ConEmu.
    conemu          = "C",

    -- Symbol to use with Nerd Fonts v3 fonts.
    -- Can be a string or a table:
                      -- String:  Use this symbol always.
    nerdfonts3      = "3",
                      -- Table:  Use second symbol "3 " with double-width icon fonts, otherwise use first symbol "3".
    nerdfonts3      = { "3", "3 " },

    -- Symbol to use with Nerd Fonts v2 fonts.
    -- Can be a string or a table:
                      -- String:  Use this symbol always.
    nerdfonts2      = "2",
                      -- Table:  Use second symbol "2 " with double-width icon fonts, otherwise use first symbol "2".
    nerdfonts2      = { "2", "2 " },

    -- Symbol to use with fonts that have Powerline characters but not Nerd Fonts icons.
    powerline       = "P",

    -- Symbol to use with Unicode fonts that don't have Powerline characters.
    unicode         = "U",

    -- Symbol to use in plain ASCII mode.
    ascii           = "A",

    -- Fallback symbol to use if none of the other available specializations are applicable.
    "F"
}

Running Actions

  • TBD

Flexprompt API Reference

  • TBD

License

clink-flex-prompt is distributed under the terms of The MIT License.

clink-flex-prompt's People

Contributors

bw1faeh0 avatar chrisant996 avatar eblis avatar ipatalas avatar ircama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

clink-flex-prompt's Issues

Prompt section coloration doesn't pick up Windows Terminal theme color changes

If I use Windows Terminal and set the theme to One Half Dark, the blue directory section doesn't colorize to match the theme as expected (it should be a lighter pastel color). I believe the time section has the same problem

p.s. love this, I had contributed a bit to the cmder-powerline-prompt but having a powerline10k type configurator is awesome

Multi color Module

There is a way to create a multi color text within a single module ?

I'd like to create something like "(green)username(yellow)@(red)computer".

Any advice?

k8s in prompt causing error

i have flexprompt_config.lua like below

flexprompt.settings.left_prompt = flexprompt.settings.left_prompt .. "{k8s}{python}"

and everything else is default setting.
when i open my cmd, im getting this error

 C:\Windows\System32 ﴱ error running kubectl.exe ❯ set KUBECONFIG=C:\kube\ml_lab.yaml                           exit  130
 C:\Windows\System32 ﴱ error running kubectl.exe ❯                                                              exit  130
prompt filter failed:
...s\mmanivannan\AppData\Local\clink\flexprompt_modules.lua:1100: attempt to concatenate local 'text' (a nil value)
stack traceback:
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1057: in function 'render_module'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1127: in function 'render_modules'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1222: in function 'render_prompts'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1380: in function <C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1379>
        {prompt.lua}: in function <{prompt.lua}:72>
        [C]: in function 'xpcall'
        {prompt.lua}: in function <{prompt.lua}:53>
        (...tail calls...)
        [C]: in function 'refilterprompt'
        {prompt.lua}: in function <{prompt.lua}:354>
        [C]: in function 'xpcall'
        {coroutines.lua}: in function <{coroutines.lua}:260>

ERROR IN LUA PROMPT FILTER
C:\Windows\System32>

any idea what i am doing wrong ?

Add support for NerdFonts v3

The NerdFonts v3 format has removed many icons, rearranged many icons, and resized many icons. The fonts now have inaccurate character cell size information for the icons.

  1. Update the flexprompt configure wizard to ask questions to figure out whether a v2 or v3 font is being used.
  2. Update the icon measurement functionality in flexprompt to add a space after double-width icons.
  3. Choose icons to use in v3 mode.
  4. Add a way in Lua code to override a group of icons or the v2/v3 mode selection, to make it easier to have a script that overrides font settings on a per-window basis.

No icon for anyconnect module

It's probably something on my end but for a while now I haven't seen the anyconnect icon in my prompt, just the description message (Connected / Disconnected) and I'm not sure where the issue is coming from.

This is my current config

-- WARNING:  This file gets overwritten by the 'flexprompt configure' wizard!
--
-- If you want to make changes, consider copying the file to
-- 'flexprompt_config.lua' and editing that file instead.

flexprompt = flexprompt or {}
flexprompt.settings = flexprompt.settings or {}
flexprompt.settings.separators = "pointed"
flexprompt.settings.flow = "concise"
flexprompt.settings.symbols =
{
    prompt =
    {
        ">",
        winterminal = "",
    },
}
flexprompt.settings.left_frame = "round"
flexprompt.settings.right_prompt = "{overtype}{exit}{duration}{python}{time:format=%a %H:%M}{anyconnect}"
flexprompt.settings.lines = "one"
flexprompt.settings.style = "classic"
flexprompt.settings.spacing = "compact"
-- flexprompt.settings.use_icons = { anyconnect=true, vpn=true, no_vpn=true }
flexprompt.settings.use_icons = true
flexprompt.settings.no_graphics = false
flexprompt.settings.use_8bit_color = true
flexprompt.settings.heads = "pointed"
flexprompt.settings.charset = "unicode"
flexprompt.settings.left_prompt = "{battery}{histlabel}{cwd}{git:nountracked}"
flexprompt.settings.right_frame = "round"
flexprompt.settings.powerline_font = true
flexprompt.settings.tails = "flat"
flexprompt.settings.frame_color = "light"
-- flexprompt.settings.symbols.cwd_git_symbol = true

I don't see any icons with either flexprompt.settings.use_icons = { anyconnect=true, vpn=true, no_vpn=true } or flexprompt.settings.use_icons = true. I also tried to forcefully disable the no_graphics flag, just in case, still no change.

image

prompt broken if git repo is broken

My system crashed during a git pull. It left the repository in a somewhat broken state. That in turn leads to the prompt crashing. It would be nice to catch any exception in the prompt code, since otherwise all terminals are broken, and an uninstallation is the only way to get a working environment.

prompt filter failed:
C:\Users\userid\AppData\Local\clink\flexprompt.lua:1843: attempt to index local 'HEAD' (a nil value)
stack traceback:
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1843: in function 'get_git_branch'
        C:\Users\userid\AppData\Local\clink\flexprompt_modules.lua:779: in function 'func'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1057: in function 'render_module'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1127: in function 'render_modules'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1222: in function 'render_prompts'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1380: in function <C:\Users\userid\AppData\Local\clink\flexprompt.lua:1379>
        {prompt.lua}: in function <{prompt.lua}:71>
        [C]: in function 'xpcall'
        {prompt.lua}: in function <{prompt.lua}:53>
        (...tail calls...)

Rainbow mode shows "pointed" label

Rainbow mode shows the "pointed" label (and not the ">" symbol)

flexprompt configure
y
y
y
3

Returns:

 c:\directory pointed ...

Classic mode works.

Feature-Request: Change Titlebar to Current Directory

Using native cmd.exe you'll be able to set your PROMPT to change the title of the console window like this

set PROMPT=$e]0;$p$e\$p$g

It will be ignored by clink (and your great extension).

Can you add an option to send the Escape codes to the terminal?

Adding to Scoop

Similar to my previous manifest for cmder-powerline-prompt, a manifest for clink-flex-prompt can be made.

{
    "homepage": "https://github.com/chrisant996/clink-flex-prompt",
    "version": "0.3",
    "license": "MIT",
    "url": "https://github.com/chrisant996/clink-flex-prompt/releases/download/v0.3/clink-flex-prompt-0.3.zip",
    "hash": "6b17afc84787ea0661d8b0f7bc5fc12d74949130c3c33fd26b533183b6914047",
    "installer": {
        "script": [
            "if (Get-Command clink -ErrorAction SilentlyContinue) {",
            "   clink installscripts $dir",
            "} elseif ($Env:CMDER_ROOT) {",
            "   & $Env:CMDER_ROOT\\vendor\\clink\\clink.bat installscripts $dir",
            "} else {",
            "   \"Clink or Cmder installation not found. Please manually install these scripts.\"",
            "}"
        ]
    },
    "uninstaller": {
        "script": [
            "if (Get-Command clink -ErrorAction SilentlyContinue) {",
            "   clink uninstallscripts $dir",
            "} elseif ($Env:CMDER_ROOT) {",
            "   & $Env:CMDER_ROOT\\vendor\\clink\\clink.bat uninstallscripts $dir",
            "}"
        ]
    },
    "checkver": "github",
    "autoupdate": {
        "url": "https://github.com/chrisant996/clink-flex-prompt/releases/download/v$version/clink-flex-prompt-$version.zip"
    }
}

If this looks good to go, I can make a PR to the Scoop bucket.

config file unsorted

I just noticed that a recently saved copy of the autoconfig.lua (then renamed to config.lua) is sorted completely differently than the current one. There is no problem as such with that. But if you use the autoconfig as base for a (reduced) config, then comparing them with a 2 way diff tool becomes not nice.

As a developer my assumption would be that the settings are stored in a set like data structure, and in many other languages sets have no explicit sort order, and need to be sorted explicitly to create some stable order during serialization.

Add documentation for how to easily use async prompt filtering.

It's very easy with flexprompt.prompt_info(), but there's no documentation yet for how to use that.


Step 1 -- Collect info to be shown in the prompt

Make a function that collects the info that should appear in the prompt.
Make the function return a table containing the info.

-- This function uses async prompt filtering to count the number
-- of files in the current directory.
local function collect_foo_info()
    local ret = {}

    local count_files = 0

    local f = io.popen("dir /b /a-d *")
    if f then
        for line in f:lines() do
            count_files = count_files + 1
        end
        f:close()
    end

    ret.count_files = count_files

    return ret
end

Step Two -- Make it collect the info asynchronously

Make a module that calls flexprompt.prompt_info().
We'll discuss the middle two parameters later -- they can be empty strings if you don't need them.

local foo_data = {}

local function foo_module(args)
    -- Use async prompt filtering to call the collect_foo_info() function.
    local info = flexprompt.prompt_info(foo_data, "", "", collect_foo_info)

    -- Build the prompt text.
    local text = info.count_files or 0
    text = flexprompt.append_text(text, flexprompt.make_fluent_text("file(s)"))
    return text, "cyan"
end

flexprompt.add_module("foo", foo_module)

Step Three -- [Optional] Maybe reset the cached prompt info

Async prompt filtering shows the previous prompt content until the async collection function finishes.

But sometimes you may know in advance that the previous prompt content is no longer relevant. There is a simple way to automatically discard the previous cached prompt content.

The flexprompt.prompt_info() function takes two parameters which, if either is different from the previous prompt, will automatically reset the cached prompt content.

For example, the {git} module passes the git repo root directory and the current git branch. This is so that if you cd to a different repo or git switch to a different branch, the prompt doesn't mislead by showing info from a different repo or branch.

So, since this sample {foo} module counts the files in the current directory, it makes sense to use the current directory for one of those two parameters:

local function foo_module(args)
    -- Use async prompt filtering to call the collect_foo_info() function.
    local info = flexprompt.prompt_info(foo_data, os.getcwd(), "", collect_foo_info)

    -- Build the prompt text.
    local text = info.count_files or 0
    text = flexprompt.append_text(text, flexprompt.make_fluent_text("file(s)"))
    return text, "cyan"
end

Step Four -- Be happy

Tada!

Lines not connecting up

Hi after playing with the Terminal a bit and testing I came across those weird lines at the end not correctly lining up even after restarting terminal and all.

Also is that big gap between user icon and name normal?
can I make that smaller?

image

Here is my flexprompt_config.lua

flexprompt = flexprompt or {}
flexprompt.settings = flexprompt.settings or {}
flexprompt.settings.charset = "unicode"
flexprompt.settings.connection = "disconnected"
flexprompt.settings.flow = "concise"
flexprompt.settings.frame_color = "dark"
flexprompt.settings.heads = "pointed"
flexprompt.settings.left_frame = "round"
flexprompt.settings.left_prompt = "{battery}{histlabel}{user}{cwd}{git}"
flexprompt.settings.lines = "two"
flexprompt.settings.nerdfonts_version = 3
flexprompt.settings.nerdfonts_width = 1
flexprompt.settings.powerline_font = true
flexprompt.settings.right_frame = "round"
flexprompt.settings.right_prompt = "{overtype}{exit}{duration}{time:format=%a %H:%M}"
flexprompt.settings.separators = "pointed"
flexprompt.settings.spacing = "sparse"
flexprompt.settings.style = "classic"
flexprompt.settings.symbols =
{
    prompt =
    {
        ">",
        winterminal = "❯",
    },
}
flexprompt.settings.tails = "flat"
flexprompt.settings.use_8bit_color = true
flexprompt.settings.use_color_emoji = true
flexprompt.settings.use_icons = true
flexprompt.settings.width = 110

suggestion: add 'flexprompt_config.lua' to .gitignore

Hi,

the flexprompt_autoconfig.lua suggests to rename/copy it to flexprompt_config.lua to avoid the content to be overwritten with the next run of flexprompt configure.
The created flexprompt_autoconfig.lua is in the gitignore of the repo to avoid changes to the repo by just using it.

I suggest you add flexprompt_config.lua to the repo, too.

Permissions Issue on winget installation

When installing clink via winget it gets written to "Programm File (x86)" If then trying to write the Config File it shows some lua error, maybe there could be a notice retry as admin or so, like you can in vscode.

Show git submodule

At the moment if you go to a folder thta is a git submodule, flex-prompt show the parent repo states/branch instead of the submodule's.
Would be gret to have parameter for the git module to get the status/branch from the submodule if present, instead of showing the parent repo.

Thanks.

[Feature request] Display state of INSERT/OVERTYPE mode

Hi,

as an user of the "overtype" feature of my keyboard (activated by INS-key) I would be happy, if the flexprompt is able to display the overtype state, because it could not be recognized based on the cursor in my (all?) terminal emulators.

powerline10K:

image
pressing [INS]
image

If you have some free time, maybe you can think about an implementation in clink/flexprompt 😄

flexprompt 0.15 | flexprompt_wizard.lua:889: attempt to index field 'symbols' (a nil value)

              Welcome to the configuration wizard for flexprompt.
            This will ask a few questions and configure your prompt.

                        Does this look like a rectangle?

                                      ┌──┐
                                 -->  │  │  <--
                                      └──┘

(y)  Yes.

(n)  No.

(r)  Restart from the beginning.
(q)  Quit and do nothing.

...\scoop\apps\clink-flex-prompt\0.15\flexprompt_wizard.lua:889: attempt to index field 'symbols' (a nil value)
'flexprompt' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Tordenflesk >                                                                                                                      9009 15s fr 18:48

Ability to ignore untracked files in git status

I usually always have some untracked files in my git repos which make the git part of the prompt never report purple (green?) status, where everything is ok and up to date.
Could we have a setting to tell it to ignore untracked files in the report, and only concentrate on files that have been added to the repository ?

Using own git module in flexprompt blocks git checkout command

Hi,

first: I think this is a problem of my custom module, not of flexprompt itself. I'm just wondering if you can point the finger on my code to show me, what I have done wrong...

I tried writing a custom module that displays the current git hash and tag name using git describe --long --always. The output looks like this:
image

The code of the flexprompt_git_describe.lua module looks like this:

-- This is the prompt module function.
local function git_describe(args)
    -- Set up the default colors, and then parse a 'color' token to override the
    -- defaults with customized colors.
    local color = "green"
    local altcolor = "black"
    local color_arg = flexprompt.parse_arg_token(args, "color")
    color, altcolor = flexprompt.parse_colors(color_arg, color, altcolor)

    git_dir = git_dir or flexprompt.get_git_dir()

    -- If git directory not found then we're probably outside of repo or
    -- something went wrong.  The same is when head_file is nil.
    local head_file = git_dir and io.open(path.join(git_dir, 'HEAD'))
    if not head_file then return end

    local file = flexprompt.popenyield("git describe --long --always 2>nul")
    local line = file:read("*l")
    file:close()
 
   if not line then return end
   return "(" .. line .. ")", color, altcolor
end

-- This registers the prompt module function with flexprompt.
-- Pass a string, and a function.
flexprompt.add_module("git-desc", git_describe)

The main problem that git is not able to checkout an other branch, because my module is blocking the HEAD file while executing this script after entering git checkout main:

 [..]\project  on   develop  (v1.0.0-2-g3d72c00)                                  
❯ git checkout main
Rename from '[..]\project/.git/HEAD.lock' to '[..]\project/.git/HEAD' failed. Should I try again? (y/n) n
error: unable to write symref for HEAD: Permission denied
fatal: unable to update HEAD

If I disable the lines

    git_dir = git_dir or flexprompt.get_git_dir()

    -- If git directory not found then we're probably outside of repo or
    -- something went wrong.  The same is when head_file is nil.
    local head_file = git_dir and io.open(path.join(git_dir, 'HEAD'))
    if not head_file then return end

from my script to disable the is-git-dir-check then the checkout works.

It seems I have some race condition here.... Do you have any hints for me?

Feature request: administrative level info

I generally run without administrative rights and use gsudo to elevate any terminal/shell when necessary. It would be great to have a module or module option to customize the prompt depending on whether the current shell is an administrative shell or not (example: red color for admin shell, normal color otherwise).

flexprompt configure unable to write to disk

re-running flexprompt-configure is not allowing me to write to the disk even if the target file is not present. also it seems as though flexprompt executable it not present

     Write new C:\Program Files (x86)\clink\flexprompt_autoconfig.lua file?

(y)  Yes.

(r)  Restart from the beginning.
(q)  Quit and do nothing.

C:\Program Files (x86)\clink\flexprompt_wizard.lua:190: Unable to write settings; unable to write to 'C:\Program Files (x86)\clink\flexprompt_autoconfig.lua'.
'flexprompt' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\manoj ❯  ```

AnyConnect module is missing support

The new AnyConnect module is missing support for some flexprompt features and modes.

What I've noticed so far:

  • Doesn't support no-icons mode.
  • Doesn't support fluent flow.
  • Colors are not configurable.
  • Contrast problems with the hard-coded colors and e.g. Classic style.

Also, @eblis, could you share the output from vpncli.exe state when a connection is established?
Is there some way to find out which connection is established, so that the name can be optionally reported in the prompt text?

I'll address most of the missing issues, but I can't find any information on vpncli commands and their output (internet searches are littered with fake sites for related keywords).

add support for k8s context rendering

when working with multiple k8s clusters it is helpful to know what cluster your current prompt is targetting.

this avoids accidently doing something in production when you intended to do it in the dev setup.

Examples

Can you add some examples that are more prominent on the readme.md or other file/folder somewhere? I learn much faster when I see an overview of how something is supposed to work, and I think most of the options are super intuitive (great job on api!!) but I'd prefer having a base to start off of through an example. If you could post even some of the prompts you have images for somewhere, I'd really appreciate it! I don't think I'll be the only one to benefit from this either :D

How to show virtualenv name before prompt

Hello! When you activate a Python virtual environment using venv or pipenv, the default CMD behavior is that the name of the virtual environment is shown before your prompt such as:
(virtual-environment-name) C:\Users\S>
But this doesn't show up on Clink, is there any way to add it to the prompt? I used the wizard to create my prompt by the way.
Thanks very much in advance.

Cisco AnyConnect VPN and PROXY connection status

The {vpn} module wasn't really working for me as I'm using Cisco AnyConnect and rasdial wasn't showing that connection.
What I really wanted to show in the command line was if there was a mismatch between my proxy environment variables and the VPN connection.
So when the VPN is connected I need to have the HTTP_PROXY and HTTPS_PROXY environment variables defined. But when the VPN is disconnected then it's better for me if the HTTP_PROXY and HTTPS_PROXY environment variables are not defined (empty) - some tools will fail if the proxies are defined and the VPN connection is not available.

I've made some changes to flexprompt_modules.lua file so it only shows a "VPN" icon and colors it according to the current status of both vpn connection and proxy env vars. Green and blue are ok states, yellow means that one of the proxies is defined but not the other, red means that there's mismatch between vpn connection status and proxy env variables definitions.

Maybe it's helpful for some else so I'm going to share it here:

local function collect_vpn_info()
    local file = flexprompt.popenyield("vpncli state")
    local line
    local conns = {}

    while true do
        line = file:read("*l")
        -- print("Candidate " .. line)
        if not line then
            break
        end
        line = line:match( "^%s*(.-)%s*$" )
        if line ~= "" and #line > 0 then
          -- print("Adding line " .. line)
          table.insert(conns, line)
        end
    end

    -- If the spawned process returned a non-zero exit code, it failed.
    local ok,what,stat = file:close()
    if not ok then
        return {}
    end

    -- Discard the last line, which says the command completed successfully.
    table.remove(conns)
    if #conns == 0 then
        return {}
    end

    -- Concatenate the connection(s) into a string.
    connected = false
    for _,candidate in ipairs(conns) do
        -- print("Checking " .. candidate)
        if candidate and #candidate > 0 and candidate:find("state") ~= nil then
            -- print("State found in " .. candidate)
            connected = (candidate:find("Disconnected") == nil)
        end
    end
    tmp = os.getenv("HTTP_PROXY")
    proxy = tmp and #tmp > 0
    tmp = os.getenv("HTTPS_PROXY")
    proxys = tmp and #tmp > 0

    return { connection=connected, proxy=proxy, proxys=proxys }
end

local function render_vpn(args)
    local info
    local refreshing
    local wizard = flexprompt.get_wizard_state()

    if wizard then
        info = { connection=false, finished=true }
    else
        -- Get connection status.
        info = flexprompt.promptcoroutine(collect_vpn_info)

        -- Use cached info until coroutine is finished.
        if not info then
            info = vpn_cached_info or {}
            refreshing = true
        else
            vpn_cached_info = info
        end
    end

    if not info then
        return
    end

    local colors = flexprompt.parse_arg_token(args, "c", "color")
    local color, altcolor
    -- print("VPN " .. (info.connection and "connected" or "disconnected") .. " HTTP proxy " .. (info.proxy and "configured" or "not configured") .. " HTTPS proxy " .. (info.proxys and "configured" or "not configured"))
    if info.connection then
        if info.proxy or info.proxys then
            if info.proxy ~= info.proxys then
                color = flexprompt.use_best_color("yellow", "38;5;11")
            else
                color = flexprompt.use_best_color("blue", "38;5;12")
            end
        else
            color = flexprompt.use_best_color("red", "38;5;9")
        end
    else
        if info.proxy or info.proxys then
            if info.proxy ~= info.proxys then
                color = flexprompt.use_best_color("yellow", "38;5;11")
            else
                color = flexprompt.use_best_color("red", "38;5;9")
            end
        else
            color = flexprompt.use_best_color("green", "38;5;2")
        end
    end

    color, altcolor = flexprompt.parse_colors(colors, color, altcolor)

    local text
    if info.connection then
        text = flexprompt.get_symbol("vpn")
    else
        text = flexprompt.get_symbol("no_vpn")
    end
    if flexprompt.get_flow() == "fluent" then
        text = flexprompt.append_text(flexprompt.make_fluent_text("over"), text)
    end
    text = flexprompt.append_text(flexprompt.get_module_symbol(refreshing), text)

    return text, color, altcolor
end

And here are the 2 icons I came up with (for copy pasting)

    vpn             = { "" },
    no_vpn          = { "" },

Configuration wizard fails "Unable to write settings"

After running flexprompt configure and answering all the questions, I get this error:

                                Transient Prompt

(y)  Yes.

     > git pull
     > git branch x
     c:\directory master 2s > git checkout x

(n)  No.

     c:\directory master 2s > git pull
     c:\directory master 2s > git branch x
     c:\directory master 2s > git checkout x

(r)  Restart from the beginning.
(q)  Quit and do nothing.

...rograms\Terminal\clink\profile\lua\flexprompt_wizard.lua:80: Unable to write settings; unable to write to '...rograms\Terminal\clink\profile\lua\flexprompt_autoconfig.lua'.
'flexprompt' is not recognized as an internal or external command,
operable program or batch file.

Exited with code 9009 in 22.282 sec

D:\Programs\Terminal\clink >                                                                                                                                                                            9009 22s Wed 08:17

I have tried creating a blank flexprompt_autoconfig.lua file as well as running as administrator. Neither helped and I keep getting the same error.
I can create the file using echo.>flexprompt_autoconfig.lua from the same console, so it is not a permission issue

flexprompt_modules.lua:112: attempt to call global 'get_style' (a nil value)

On one of my machines, I got this error when starting clink:
(on my other machine it is working without problems)

prompt filter failed:
C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: attempt to call global 'get_style' (a nil value)
stack traceback:
        C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:91>
        (...tail calls...)
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:821: in function 'render_modules'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:925: in function 'render_prompts'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1043: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1042>
        ?: in function <?:37>
        [C]: in function 'xpcall'
        ?: in function <?:24>
        (...tail calls...)

prompt filter failed:
C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: attempt to call global 'get_style' (a nil value)
stack traceback:
        C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:91>
        (...tail calls...)
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:821: in function 'render_modules'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:925: in function 'render_prompts'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1043: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1042>
        ?: in function <?:37>
        [C]: in function 'xpcall'
        ?: in function <?:24>
        (...tail calls...)
        [C]: in function 'resume'
        ?: in function <?:187>
        [C]: in function 'xpcall'
        ?: in function <?:180>

prompt filter failed:
C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: attempt to call global 'get_style' (a nil value)
stack traceback:
        C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:112: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt_modules.lua:91>
        (...tail calls...)
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:821: in function 'render_modules'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:925: in function 'render_prompts'
        C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1043: in function <C:\Users\bw1faeh0\configFiles\clink\flexprompt.lua:1042>
        ?: in function <?:37>
        [C]: in function 'xpcall'
        ?: in function <?:24>
        (...tail calls...)
        [C]: in function 'resume'
        ?: in function <?:187>
        [C]: in function 'xpcall'
        ?: in function <?:180>

Clink Version: v1.2.32
flexprompt version: e063850 (I know, it was no release, but I tried it out)

Feature request: Add env var module

Would be great to be able to do something like this out of the box:

flexprompt.settings.left_prompt = "{env:HOSTNAME:color=magenta}{cwd}"

[vpn module] rasdial is localized, string compare won't work on non-english systems

Hi,

I just took a look at the code of the vpn module for curiosity to get an idea how you are trying to check VPN connections (which I often use).
I tested the output of rasdial. Beside the fact, that I'm connected via custom VPN solution (zscaler), the output of rasdial is in german, so your string compare would always fail:

if line ~= "Connected to" then

Font vs. Unicode

Hi,

If I'm not totaly wrong, you can't guess from the diamond question in the config script the support of unicode or not. I'm using windows terminal, which supports unicode afaik, but I could not see the diamond because my font (cascadia code) has no diamonds ;)

I suggest, that you recommend a font (like powerlevel10k does) or link to nerdfonts.com in your readme.

Meanwhile I switched to Meslo Nerd Font as described by powerlevel10k.

Feature request: Add java version in flexprompt

Java version can be obtained by running java -version
Which return a line such as

java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

For an example implementation, starship shell java module uses a Rust regular expression for that: (?:JRE.*\\(|OpenJ9 )(?P<version>[\\d]+(?:\\.\\d+){0,2})

Table icons doesn't seem to work ?

I either haven't configured table icons correctly or they don't work as intended.
I want to use icons, but just for anyconnect module, for vpn and no_vpn.

I've added this flexprompt.settings.use_icons = { "anyconnect", "vpn", "no_vpn" }, but I still don't get any icons.
I've modified the flexprompt.lua file to add some print statements, like so:

local function get_icon(name)
    if not flexprompt.settings.use_icons then return "" end
    tprint(flexprompt.settings.use_icons)
    print("get icon " .. name)
    if flexprompt.settings.use_icons[name] then
        print("\tenabled " .. name)
    else
        print("\tdisabled " .. name)
    end
    if type(flexprompt.settings.use_icons) == "table" and not flexprompt.settings.use_icons[name] then return "" end
    print("result get icon " .. name)

    return get_symbol(name)
end

And this is the output i see for the vpn icons:
image

flexprompt_config.lua: attempt to index global 'flexprompt' (a nil value)

I have the following flexprompt_config.lua file:

flexprompt.settings.git_fetch_interval = 15
flexprompt.settings.duration_threshold = 1

When launching 1 instance of windows terminal (clink autorun) it all works fine.

Today, I started playing around with creating split panes on startup. Sometimes that produces this error:

attempt to index global 'flexprompt' (a nil value)

I'm launching multiple terminals via this invocation of wt.exe:

# nt - create a new tab
# sp - split that tab Horiz and duplicate previous pane
wt nt ; sp -H -D 

Clearly one session is stomping on the other. I don't know enough Lua to come up with a fix.

Resizing terminal breaks prompt

Hi
I just this discovered this awesome, prompt, I just looks amazing, thanks!

Sadly when resizing the terminal the lines get quite messed up, is this something fixable?
image

RFE: ability to shorten CWD exlcuding any git repo paths

It would be great if flexprompt had the ability to shorten the cwd but only shorten directories outside of a gitroot.

e.g. if the cwd was C:\workarea\source\github\jenkinsci\acceptance-test-harness\src\main\java\org\jenkinsci\test and acceptance-test-harness was the directory containing a clone of jenkinsci\acceptancetest-harness
currently if the shorten is used (with rootsmart) you have

C:\w\s\g\j\a\s\m\j\o\j\test

Ideally I would like a way to shorten only the directories outside of the git root

so the above would become

C:\w\s\g\j\acceptance-test-harness\src\main\java\org\jenkinsci\test

if used outside of a git (SCM?) root then the prompt would be shortened as normally so that any directory except the last would be shortened.

flexprompt configure crashes (?) when resizing console windows

Hi,

I just notices a small issue:
When I run flexprompt configure and answer the questions the wizard exits (without any error message or similar) if I resize the console window.
I observed this behavior in Windows Terminal as well as the classic windows cmd.

No big deal for me, but I just wanted to document this bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.