예제 #1
0
    async def coro(knobs,
                   path=iterm2.Reference("path"),
                   cwd=iterm2.Reference("user.currentDir?")):
        import os
        import json
        from pathlib import Path

        currentDir = path
        if 'force-app' in currentDir:  # User is in subdirectory
            currentDir = currentDir.split('force-app')[
                0]  # Get root directory of project folder
        if Path(currentDir + '/sfdx-project.json').is_file(
        ):  # Current folder is sfdx folder
            # Retrieve defaultusername = alias
            dir = currentDir if Path(
                currentDir + '/.sfdx/sfdx-config.json'
            ).is_file() else os.environ[
                'HOME']  # Get config from project folder if present, or global config
            with open(dir + '/.sfdx/sfdx-config.json') as configFile:
                config = json.load(configFile)
            global aliasOrUsername
            aliasOrUsername = config['defaultusername']

            # Retrieve username for alias
            with open(os.environ['HOME'] + '/.sfdx/alias.json') as aliasFile:
                alias = json.load(aliasFile)

            if 'defaultusername' in config and 'orgs' in alias:
                return u'\u2601 ' + config[
                    'defaultusername'] + u' \u2022 ' + alias['orgs'][
                        config['defaultusername']]
            else:
                return u'\u2601'  # Some error occurred, e.g. file not found or wrong content
        else:
            return u'\u2601'  # No SFDX directory
예제 #2
0
    async def georges_title(pwd=iterm2.Reference("path?"),
                            tmux_title=iterm2.Reference("tmuxWindowTitle?"),
                            user_home=iterm2.Reference("user.home?")):
        if tmux_title:
            return tmux_title

        return make_pwd(user_home, localhome, pwd)
예제 #3
0
    async def coro(
            knobs,
            rows=iterm2.Reference("rows"),
            cols=iterm2.Reference("columns")):
        status_delimiter = '-~`/='
        ascript = '''
            tell application "System Events"
                set process_list to (name of every process)
            end tell

            if process_list contains "Music" then
                tell application "Music"
                    set t_title to name of current track
                    set t_artist to artist of current track
                    set t_album to album of current track
                    set t_duration to duration of current track
                    set t_elapsed to player position
                    set t_state to player state
                    return t_title & "{0}" & t_artist & "{0}" & t_album & "{0}" & t_elapsed & "{0}" & t_duration & "{0}" & t_state
                    end tell
            end if
        '''.format(status_delimiter)
        now_playing = asrun(ascript)
        if not now_playing:
            return ""
        now_playing = now_playing.split(status_delimiter)
        if len(now_playing) != 6:
            return
        title, artist, album = now_playing[0], now_playing[1], now_playing[2]
        state = _convert_state(now_playing[5])
        total = _convert_seconds(now_playing[4].replace(',', '.'))
        elapsed = _convert_seconds(now_playing[3].replace(',', '.'))

        return "{} {} - {} {}/{}".format(state, artist, title, elapsed, total)
예제 #4
0
    async def tab_title_fixed_hostname(
            hostname=iterm2.Reference("hostname?"),
            user_hostname=iterm2.Reference("user.hostname?"),
            user_remote_hostname=iterm2.Reference("user.remote_hostname?"),
            auto_name=iterm2.Reference("autoName?"),
            profile_name=iterm2.Reference("profileName?")):

        if user_remote_hostname:
            return user_remote_hostname

        if user_hostname:
            return user_hostname

        return make_hostname(hostname, localhost)
    async def cuda_version(knobs, nvcc=iterm2.Reference('user.cuda_ver?')):
        if not nvcc:
            return "CUDA UNAVAILABLE"
        else:
            try:
                ver_str = nvcc.split('release')[-1]
                ver_str = ver_str.split(',')[0].split()[0]
            except:
                return "CUDA ERROR"

            show_cuda_version = "CUDA Ver. {}".format(ver_str)
            return show_cuda_version
예제 #6
0
    async def coro(knobs,
                   rows=iterm2.Reference("rows"),
                   cols=iterm2.Reference("columns")):
        status_delimiter = '-~`/='
        ascript = '''
          tell application "System Events"
            set process_list to (name of every process)
          end tell

          if process_list contains "Spotify" then
            tell application "Spotify"
              if player state is playing or player state is paused then
                set track_name to name of current track
                set artist_name to artist of current track
                set album_name to album of current track
                set track_length to duration of current track
                set now_playing to "" & player state & "{0}" & album_name & "{0}" & artist_name & "{0}" & track_name & "{0}" & track_length & "{0}" & player position
                return now_playing
              else
                return player state
              end if
            end tell
          end if
        '''.format(status_delimiter)
        spotify = asrun(ascript)
        if not spotify:
            return ""

        spotify_status = spotify.split(status_delimiter)
        state = _convert_state(spotify_status[0])
        if state == 'stop':
            return None

        artist = spotify_status[2]
        title = spotify_status[3]
        total = _convert_seconds(
            int(spotify_status[4].replace(',', '.')) / 1000)
        elapsed = _convert_seconds(spotify_status[5].replace(',', '.'))
        return "{} {} - {} {}/{}".format(state, artist, title, elapsed, total)
예제 #7
0
    async def weather(knobs,
                      value=iterm2.Reference("iterm2.user." +
                                             CURRENT_VARIABLE + "?")):
        """This function returns the value to show in a status bar."""
        global city
        global update_interval
        if location_knob in knobs and knobs[location_knob]:
            city = knobs[location_knob]
        if update_interval_knob in knobs and knobs[update_interval_knob]:
            update_interval = int(knobs[update_interval_knob])

        if value:
            return value
        return "Loading…"
예제 #8
0
 async def pyenv_coroutine(knobs, python=iterm2.Reference('user.python_version?')):
     python = python or '☠️'
     return f'🐍 {python}'
예제 #9
0
 async def term_size(knobs,
                     rows=iterm2.Reference("rows"),
                     columns=iterm2.Reference("columns")):
     return "{}x{}".format(columns, rows)
예제 #10
0
 async def rvm_gemset_coroutine(
     knobs, ruby=iterm2.Reference('user.ruby_version?')):
     ruby = ruby or 'default'
     ruby = ruby.replace('@', '') or 'default'
     return f'💎 {ruby}'
예제 #11
0
 async def coro(knobs, cputemp=iterm2.Reference("iterm2.user.cputemp?")):
     return GetTemp() + "    ☢  " + GetFan()
예제 #12
0
 async def disk_io_coroutine(knobs, value=iterm2.Reference("iterm2.user." + DISK_IO_VARIABLE + "?")):
     """This function returns the value to show in a status bar."""
     if value:
         return value
     return "Loading…"
 async def coro(knobs, version=iterm2.Reference("user.asdfRubyVersion?")):
     if version:
         return f'💎 {version}'
     else:
         return "❌"