Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance run_segment function to handle long, short, and custom hostname options #456

Open
farheinheigt opened this issue Dec 23, 2024 · 0 comments

Comments

@farheinheigt
Copy link

Hi,

I’d like to propose an improvement to the run_segment function within the hostname.sh file. Currently, the function supports fetching the hostname in “short” or “long” format. However, it would be beneficial to add support for a custom option that allows users to pass a predefined string to be displayed instead of the actual hostname.

Proposed Changes

1. Enhance run_segment

The function is updated to handle three cases: “short”, “long”, and a “custom” option. Here’s the modified code for the run_segment function:

run_segment() {
    local opts=""
    if [ "$TMUX_POWERLINE_SEG_HOSTNAME_FORMAT" == "short" ]; then
        if shell_is_osx || shell_is_bsd; then
            opts="-s"
        else
            opts="--short"
        fi
        # Display the hostname in short format
        hostname ${opts}
        return 0
    elif [ "$TMUX_POWERLINE_SEG_HOSTNAME_FORMAT" == "long" ]; then
        # Display the hostname in long format (default)
        hostname
        return 0
    else
        # If neither "short" nor "long", display the custom string
        echo "$TMUX_POWERLINE_SEG_HOSTNAME_FORMAT"
        return 0
    fi
}

2. Update config.sh

To support the new “custom” option, update the hostname.sh configuration example as follows:

# hostname.sh {
    # Use short, long, or custom format for the hostname. Can be {"short", "long", "custom"}.
    export TMUX_POWERLINE_SEG_HOSTNAME_FORMAT="MYLAPTOP"
# }

Example Behavior

  • When TMUX_POWERLINE_SEG_HOSTNAME_FORMAT="short":
    Output: hostname -s

  • When TMUX_POWERLINE_SEG_HOSTNAME_FORMAT="long":
    Output: hostname

  • When TMUX_POWERLINE_SEG_HOSTNAME_FORMAT="MYLAPTOP":
    Output: MYLAPTOP

Benefits

  • Adds flexibility for users who want to display a custom string instead of their system hostname.
  • Updates the configuration file to make the custom option visible and easy to use.
  • Maintains backward compatibility for “short” and “long” options.

Request

If this sounds like a valuable enhancement, I’d be happy to collaborate further or submit a Pull Request with the implementation. Let me know your thoughts!

Thanks for considering this suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant