Common segments¶
VCS submodule¶
System properties¶
- powerline.segments.common.sys.system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, track_cpu_count=False, short=False)[source]¶
Return system load average.
Highlights using
system_load_good,system_load_badandsystem_load_uglyhighlighting groups, depending on the thresholds passed to the function.- Parameters:
format (str) – format string, receives
avgas an argumentthreshold_good (float) – threshold for gradient level 0: any normalized load average below this value will have this gradient level.
threshold_bad (float) – threshold for gradient level 100: any normalized load average above this value will have this gradient level. Load averages between
threshold_goodandthreshold_badreceive gradient level that indicates relative position in this interval: (100 * (cur-good) / (bad-good)). Note: both parameters are checked against normalized load averages.track_cpu_count (bool) – if True powerline will continuously poll the system to detect changes in the number of CPUs.
short (bool) – if True only the sys load over last 1 minute will be displayed.
Divider highlight group used:
background:divider.Highlight groups used:
system_load_gradient(gradient) orsystem_load.
- powerline.segments.common.sys.uptime(pl, days_format='{days:d}d', hours_format=' {hours:d}h', minutes_format=' {minutes:02d}m', seconds_format=' {seconds:02d}s', shorten_len=3)[source]¶
Return system uptime.
- Parameters:
days_format (str) – day format string, will be passed
daysas the argumenthours_format (str) – hour format string, will be passed
hoursas the argumentminutes_format (str) – minute format string, will be passed
minutesas the argumentseconds_format (str) – second format string, will be passed
secondsas the argumentshorten_len (int) – shorten the amount of units (days, hours, etc.) displayed
Divider highlight group used:
background:divider.
Network¶
- powerline.segments.common.net.hostname(pl, segment_info, only_if_ssh=False, exclude_domain=False)[source]¶
Return the current hostname.
- Parameters:
only_if_ssh (bool) – only return the hostname if currently in an SSH session
exclude_domain (bool) – return the hostname without domain if there is one
- powerline.segments.common.net.internal_ip(pl, interface='auto', ipv=4)[source]¶
Return internal IP address
Requires
netifacesmodule to work properly.- Parameters:
interface (str) –
Interface on which IP will be checked. Use
autoto automatically detect interface. In this case interfaces with lower numbers will be preferred over interfaces with similar names. Order of preference based on names:ethandenpfollowed by number or the end of string.ath,wlanandwlpfollowed by number or the end of string.teredofollowed by number or the end of string.Any other interface that is not
lo*.lofollowed by number or the end of string.
Use
default_gatewayto detect the interface based on the machine’s default gateway (i.e., the router to which it is connected).ipv (int) – 4 or 6 for ipv4 and ipv6 respectively, depending on which IP address you need exactly.
Current environment¶
- class powerline.segments.common.env.CwdSegment[source]¶
- powerline.segments.common.env.environment(pl, segment_info, variable=None)[source]¶
Return the value of any defined environment variable
- Parameters:
variable (string) – The environment variable to return if found
- powerline.segments.common.env.user(pl, segment_info, hide_user=None, hide_domain=False)[source]¶
Return the current user.
- Parameters:
hide_user (str) – Omit showing segment for users with names equal to this string.
hide_domain (bool) – Drop domain component if it exists in a username (delimited by ‘@’).
Highlights the user with the
superuserif the effective user ID is 0.Highlight groups used:
superuseroruser. It is recommended to define all highlight groups.
- powerline.segments.common.env.virtualenv(pl, segment_info, ignore_venv=False, ignore_conda=False, ignored_names=('venv', '.venv'))[source]¶
Return the name of the current Python or conda virtualenv. :param list ignored_names:
Names of venvs to ignore. Will then get the name of the venv by ascending to the parent directory
- Parameters:
ignore_venv (bool) – Whether to ignore virtual environments. Default is False.
ignore_conda (bool) – Whether to ignore conda environments. Default is False.
Battery¶
- powerline.segments.common.bat.battery(pl, format='{ac_state} {capacity:3.0%}', steps=5, gamify=False, full_heart='O', empty_heart='O', online='C', offline=' ')[source]¶
Return battery charge status.
- Parameters:
format (str) – Percent format in case gamify is False. Format arguments:
ac_statewhich is equal to eitheronlineorofflinestring arguments andcapacitywhich is equal to current battery capacity in interval [0, 100].steps (int) – Number of discrete steps to show between 0% and 100% capacity if gamify is True.
gamify (bool) – Measure in hearts (♥) instead of percentages. For full hearts
battery_fullhighlighting group is preferred, for empty hearts there isbattery_empty.battery_onlineorbattery_offlinegroup will be used for leading segment containingonlineorofflineargument contents.full_heart (str) – Heart displayed for “full” part of battery.
empty_heart (str) – Heart displayed for “used” part of battery. It is also displayed using another gradient level and highlighting group, so it is OK for it to be the same as full_heart as long as necessary highlighting groups are defined.
online (str) – Symbol used if computer is connected to a power supply.
offline (str) – Symbol used if computer is not connected to a power supply.
battery_gradientandbatterygroups are used in any case, first is preferred.Highlight groups used:
battery_fullorbattery_gradient(gradient) orbattery,battery_emptyorbattery_gradient(gradient) orbattery,battery_onlineorbattery_ac_stateorbattery_gradient(gradient) orbattery,battery_offlineorbattery_ac_stateorbattery_gradient(gradient) orbattery.
Weather¶
Date and time¶
- powerline.segments.common.time.date(pl, format='%Y-%m-%d', istime=False, timezone=None)[source]¶
Return the current date.
- Parameters:
format (str) – strftime-style date format string
istime (bool) – If true then segment uses
timehighlight group.timezone (string) – Specify a timezone to use as
+HHMMor-HHMM. (Defaults to system defaults.)
Divider highlight group used:
time:divider.Highlight groups used:
timeordate.
- powerline.segments.common.time.fuzzy_time(pl, format=None, unicode_text=False, timezone=None, hour_str=['twelve', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven'], minute_str={'0': "{hour_str} o'clock", '10': 'ten past {hour_str}', '15': 'quarter past {hour_str}', '20': 'twenty past {hour_str}', '25': 'twenty-five past {hour_str}', '30': 'half past {hour_str}', '35': 'twenty-five to {hour_str}', '40': 'twenty to {hour_str}', '45': 'quarter to {hour_str}', '5': 'five past {hour_str}', '50': 'ten to {hour_str}', '55': 'five to {hour_str}'}, special_case_str={'(0, 0)': 'midnight', '(0, 1)': 'round about midnight', '(0, 2)': 'round about midnight', '(12, 0)': 'noon', '(23, 58)': 'round about midnight', '(23, 59)': 'round about midnight'})[source]¶
Display the current time as fuzzy time, e.g. “quarter past six”.
- Parameters:
format (string) – (unused)
unicode_text (bool) – If true then hyphenminuses (regular ASCII
-) and single quotes are replaced with unicode dashes and apostrophes.timezone (string) – Specify a timezone to use as
+HHMMor-HHMM. (Defaults to system defaults.)hour_str (string list) – Strings to be used to display the hour, starting with midnight. (This list may contain 12 or 24 entries.)
minute_str (dict) – Dictionary mapping minutes to strings to be used to display them. Each entry may optionally come with a format field “{hour_str}” to indicate the position of the string used for the current hour.
special_case_str (dict) – Special strings for special times.
Highlight groups used:
fuzzy_time.
Mail¶
Media players¶
- class powerline.segments.common.players.CmusPlayerSegment[source]¶
- get_player_status(pl)[source]¶
Return cmus player information.
- cmus-remote -Q returns data with multi-level information i.e.
status playing file <file_name> tag artist <artist_name> tag title <track_title> tag .. tag n set continue <true|false> set repeat <true|false> set .. set n
For the information we are looking for we don’t really care if we’re on the tag level or the set level. The dictionary comprehension in this method takes anything in ignore_levels and brings the key inside that to the first level of the dictionary.
- class powerline.segments.common.players.MocPlayerSegment[source]¶
- get_player_status(pl)[source]¶
Return Music On Console (mocp) player information.
mocp -ireturns current information i.e.File: filename.format Title: full title Artist: artist name SongTitle: song title Album: album name TotalTime: 00:00 TimeLeft: 00:00 TotalSec: 000 CurrentTime: 00:00 CurrentSec: 000 Bitrate: 000kbps AvgBitrate: 000kbps Rate: 00kHz
For the information we are looking for we don’t really care if we have extra-timing information or bit rate level. The dictionary comprehension in this method takes anything in ignore_info and brings the key inside that to the right info of the dictionary.