def webdevicons(pl, segment_info):
	webdevicons = vim_get_func('WebDevIconsGetFileTypeSymbol')
	name = buffer_name(segment_info)
	return [] if not webdevicons else [{
		'contents': webdevicons(name),
		'highlight_groups': ['webdevicons', 'file_name'],
		}]
Beispiel #2
0
def file_directory(pl,
                   segment_info,
                   shorten_user=True,
                   shorten_cwd=True,
                   shorten_home=False):
    '''Return file directory (head component of the file path).

	:param bool shorten_user:
		shorten ``$HOME`` directory to :file:`~/`

	:param bool shorten_cwd:
		shorten current directory to :file:`./`

	:param bool shorten_home:
		shorten all directories in :file:`/home/` to :file:`~user/` instead of :file:`/home/user/`.
	'''
    name = buffer_name(segment_info['buffer'])
    if not name:
        return None
    file_directory = vim_funcs['fnamemodify'](
        name,
        (':~' if shorten_user else '') + (':.' if shorten_cwd else '') + ':h')
    if not file_directory:
        return None
    if shorten_home and file_directory.startswith('/home/'):
        file_directory = b'~' + file_directory[6:]
    file_directory = file_directory.decode('utf-8',
                                           'powerline_vim_strtrans_error')
    return file_directory + os.sep
Beispiel #3
0
def branch(pl, segment_info, create_watcher, status_colors=False):
    '''Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	'''
    name = buffer_name(segment_info)
    skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
    if not skip:
        repo = guess(path=name, create_watcher=create_watcher)
        if repo is not None:
            branch = repo.branch()
            scol = ['branch']
            if status_colors:
                status = tree_status(repo, pl)
                scol.insert(
                    0, 'branch_dirty'
                    if status and status.strip() else 'branch_clean')
            return [{
                'contents': branch,
                'highlight_group': scol,
                'divider_highlight_group': 'branch:divider',
            }]
Beispiel #4
0
def file_directory(pl,
                   segment_info,
                   shorten_user=True,
                   shorten_cwd=True,
                   shorten_home=False):
    '''Return file directory (head component of the file path).

	:param bool shorten_user:
		shorten ``$HOME`` directory to :file:`~/`

	:param bool shorten_cwd:
		shorten current directory to :file:`./`

	:param bool shorten_home:
		shorten all directories in :file:`/home/` to :file:`~user/` instead of :file:`/home/user/`.
	'''
    name = buffer_name(segment_info['buffer'])
    if not name:
        return None
    file_directory = vim_funcs['fnamemodify'](
        name,
        (':~' if shorten_user else '') + (':.' if shorten_cwd else '') + ':h')
    if not file_directory:
        return None
    if shorten_home and file_directory.startswith('/home/'):
        file_directory = b'~' + file_directory[6:]
    file_directory = file_directory.decode('utf-8',
                                           'powerline_vim_strtrans_error')
    return file_directory + os.sep
Beispiel #5
0
def branch(pl, segment_info, create_watcher, status_colors=False):
	'''Return the current working branch.

	:param bool status_colors:
		determines whether repository status will be used to determine highlighting. Default: False.

	Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``.

	Divider highlight group used: ``branch:divider``.
	'''
	name = buffer_name(segment_info)
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			branch = repo.branch()
			scol = ['branch']
			if status_colors:
				status = tree_status(repo, pl)
				scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean')
			return [{
				'contents': branch,
				'highlight_group': scol,
				'divider_highlight_group': 'branch:divider',
			}]
Beispiel #6
0
def file_mtime(pl, segment_info):
	'''Return file mtime.
	'''
	name = buffer_name(segment_info)
	if os.path.isfile(name):
		return [{
			'contents': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.stat(name).st_mtime)),
			'highlight_group': ['file_mtime', 'file_size']
			}]
	else:
		return None
Beispiel #7
0
def file_mtime(pl, segment_info):
    '''Return file mtime.
	'''
    name = buffer_name(segment_info)
    if os.path.isfile(name):
        return [{
            'contents':
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(os.stat(name).st_mtime)),
            'highlight_group': ['file_mtime', 'file_size']
        }]
    else:
        return None
Beispiel #8
0
def file_name(pl, segment_info, display_no_file=False, no_file_text="[No file]"):
    """Return file name (tail component of the file path).

	:param bool display_no_file:
		display a string if the buffer is missing a file name
	:param str no_file_text:
		the string to display if the buffer is missing a file name

	Highlight groups used: ``file_name_no_file`` or ``file_name``, ``file_name``.
	"""
    name = buffer_name(segment_info["buffer"])
    if not name:
        if display_no_file:
            return [{"contents": no_file_text, "highlight_group": ["file_name_no_file", "file_name"]}]
        else:
            return None
    return os.path.basename(name).decode("utf-8", "powerline_vim_strtrans_error")
Beispiel #9
0
def file_directory(pl,
                   segment_info,
                   remove_scheme=True,
                   shorten_user=True,
                   shorten_cwd=True,
                   shorten_home=False):
    '''Return file directory (head component of the file path).

	:param bool remove_scheme:
		Remove scheme part from the segment name, if present. See documentation
		of file_scheme segment for the description of what scheme is. Also
		removes the colon.

	:param bool shorten_user:
		Shorten ``$HOME`` directory to :file:`~/`. Does not work for files with
		scheme.

	:param bool shorten_cwd:
		Shorten current directory to :file:`./`. Does not work for files with
		scheme present.

	:param bool shorten_home:
		Shorten all directories in :file:`/home/` to :file:`~user/` instead of
		:file:`/home/user/`. Does not work for files with scheme present.
	'''
    name = buffer_name(segment_info)
    if not name:
        return None
    match = SCHEME_RE.match(name)
    if match:
        if remove_scheme:
            name = name[len(match.group(0)) + 1:]  # Remove scheme and colon
        file_directory = vim_funcs['fnamemodify'](name, ':h')
    else:
        file_directory = vim_funcs['fnamemodify'](
            name, (':~' if shorten_user else '') +
            (':.' if shorten_cwd else '') + ':h')
        if not file_directory:
            return None
        if shorten_home and file_directory.startswith('/home/'):
            file_directory = b'~' + file_directory[6:]
    file_directory = file_directory.decode(segment_info['encoding'],
                                           'powerline_vim_strtrans_error')
    return file_directory + os.sep
Beispiel #10
0
def file_name(pl, segment_info, display_no_file=False, no_file_text='[No file]'):
	'''Return file name (tail component of the file path).

	:param bool display_no_file:
		display a string if the buffer is missing a file name
	:param str no_file_text:
		the string to display if the buffer is missing a file name

	Highlight groups used: ``file_name_no_file`` or ``file_name``, ``file_name``.
	'''
	name = buffer_name(segment_info)
	if not name:
		if display_no_file:
			return [{
				'contents': no_file_text,
				'highlight_groups': ['file_name_no_file', 'file_name'],
			}]
		else:
			return None
	return os.path.basename(name).decode(segment_info['encoding'], 'powerline_vim_strtrans_error')
Beispiel #11
0
def file_name(pl, segment_info, display_no_file=False, no_file_text='[No file]'):
	'''Return file name (tail component of the file path).

	:param bool display_no_file:
		display a string if the buffer is missing a file name
	:param str no_file_text:
		the string to display if the buffer is missing a file name

	Highlight groups used: ``file_name_no_file`` or ``file_name``, ``file_name``.
	'''
	name = buffer_name(segment_info)
	if not name:
		if display_no_file:
			return [{
				'contents': no_file_text,
				'highlight_groups': ['file_name_no_file', 'file_name'],
			}]
		else:
			return None
	return os.path.basename(name).decode(segment_info['encoding'], 'powerline_vim_strtrans_error')
Beispiel #12
0
def file_vcs_status(pl, segment_info, create_watcher):
	'''Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	'''
	name = buffer_name(segment_info)
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_groups': ['file_vcs_status_' + status, 'file_vcs_status'],
				})
			return ret
Beispiel #13
0
def file_vcs_status(pl, segment_info, create_watcher):
	'''Return the VCS status for this buffer.

	Highlight groups used: ``file_vcs_status``.
	'''
	name = buffer_name(segment_info)
	skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
	if not skip:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			status = repo.status(os.path.relpath(name, repo.directory))
			if not status:
				return None
			status = status.strip()
			ret = []
			for status in status:
				ret.append({
					'contents': status,
					'highlight_groups': ['file_vcs_status_' + status, 'file_vcs_status'],
				})
			return ret
Beispiel #14
0
def file_directory(pl, segment_info, remove_scheme=True, shorten_user=True, shorten_cwd=True, shorten_home=False):
	'''Return file directory (head component of the file path).

	:param bool remove_scheme:
		Remove scheme part from the segment name, if present. See documentation 
		of file_scheme segment for the description of what scheme is. Also 
		removes the colon.

	:param bool shorten_user:
		Shorten ``$HOME`` directory to :file:`~/`. Does not work for files with 
		scheme.

	:param bool shorten_cwd:
		Shorten current directory to :file:`./`. Does not work for files with 
		scheme present.

	:param bool shorten_home:
		Shorten all directories in :file:`/home/` to :file:`~user/` instead of 
		:file:`/home/user/`. Does not work for files with scheme present.
	'''
	name = buffer_name(segment_info)
	if not name:
		return None
	match = SCHEME_RE.match(name)
	if match:
		if remove_scheme:
			name = name[len(match.group(0)) + 1:]  # Remove scheme and colon
		file_directory = vim_funcs['fnamemodify'](name, ':h')
	else:
		file_directory = vim_funcs['fnamemodify'](
			name,
			(':~' if shorten_user else '') + (':.' if shorten_cwd else '') + ':h'
		)
		if not file_directory:
			return None
		if shorten_home and file_directory.startswith('/home/'):
			file_directory = b'~' + file_directory[6:]
	file_directory = file_directory.decode(segment_info['encoding'], 'powerline_vim_strtrans_error')
	return file_directory + os.sep
Beispiel #15
0
def file_scheme(pl, segment_info):
    '''Return the protocol part of the file.

	Protocol is the part of the full filename just before the colon which
	starts with a latin letter and contains only latin letters, digits, plus,
	period or hyphen (refer to `RFC3986
	<http://tools.ietf.org/html/rfc3986#section-3.1>`_ for the description of
	URI scheme). If there is no such a thing ``None`` is returned, effectively
	removing segment.

	.. note::
		Segment will not check  whether there is ``//`` just after the
		colon or if there is at least one slash after the scheme. Reason: it is
		not always present. E.g. when opening file inside a zip archive file
		name will look like :file:`zipfile:/path/to/archive.zip::file.txt`.
		``file_scheme`` segment will catch ``zipfile`` part here.
	'''
    name = buffer_name(segment_info)
    if not name:
        return None
    match = SCHEME_RE.match(name)
    if match:
        return match.group(0).decode('ascii')
Beispiel #16
0
def file_scheme(pl, segment_info):
	'''Return the protocol part of the file.

	Protocol is the part of the full filename just before the colon which 
	starts with a latin letter and contains only latin letters, digits, plus, 
	period or hyphen (refer to `RFC3986 
	<http://tools.ietf.org/html/rfc3986#section-3.1>`_ for the description of 
	URI scheme). If there is no such a thing ``None`` is returned, effectively 
	removing segment.

	.. note::
		Segment will not check  whether there is ``//`` just after the 
		colon or if there is at least one slash after the scheme. Reason: it is 
		not always present. E.g. when opening file inside a zip archive file 
		name will look like :file:`zipfile:/path/to/archive.zip::file.txt`. 
		``file_scheme`` segment will catch ``zipfile`` part here.
	'''
	name = buffer_name(segment_info)
	if not name:
		return None
	match = SCHEME_RE.match(name)
	if match:
		return match.group(0).decode('ascii')
Beispiel #17
0
def repo_directory(pl, segment_info, create_watcher):
	name = buffer_name(segment_info)
	file_directory = vim_funcs['fnamemodify'](name, ':h')
	if not name:
		return None
	match = SCHEME_RE.match(name)
	if match:
		repo_directory = file_directory
	else:
		repo = guess(path=name, create_watcher=create_watcher)
		if repo is not None:
			directory_to_sub = vim_funcs['fnamemodify'](repo.directory, ':h:h') + os.sep
			repo_directory = repo.directory
		else:
			repo_directory = vim_funcs['fnamemodify'](name, ':h')
			directory_to_sub = vim_funcs['fnamemodify'](repo_directory, ':h:h')
			if directory_to_sub != '/':
				directory_to_sub = directory_to_sub + os.sep
		repo_directory = repo_directory[len(directory_to_sub):]
	repo_directory = repo_directory.decode(segment_info['encoding'], 'powerline_vim_strtrans_error')
	return [{
		'contents': repo_directory,
		'highlight_groups': ['repo_directory', 'file_name'],
		}]
Beispiel #18
0
def file_directory(pl, segment_info, shorten_user=True, shorten_cwd=True, shorten_home=False):
    """Return file directory (head component of the file path).

	:param bool shorten_user:
		shorten ``$HOME`` directory to :file:`~/`

	:param bool shorten_cwd:
		shorten current directory to :file:`./`

	:param bool shorten_home:
		shorten all directories in :file:`/home/` to :file:`~user/` instead of :file:`/home/user/`.
	"""
    name = buffer_name(segment_info["buffer"])
    if not name:
        return None
    file_directory = vim_funcs["fnamemodify"](
        name, (":~" if shorten_user else "") + (":." if shorten_cwd else "") + ":h"
    )
    if not file_directory:
        return None
    if shorten_home and file_directory.startswith("/home/"):
        file_directory = b"~" + file_directory[6:]
    file_directory = file_directory.decode("utf-8", "powerline_vim_strtrans_error")
    return file_directory + os.sep
Beispiel #19
0
	def get_directory(segment_info):
		if vim_getbufoption(segment_info, 'buftype'):
			return None
		return buffer_name(segment_info)
Beispiel #20
0
def nerdtree(matcher_info):
	name = buffer_name(matcher_info)
	return name and NERD_TREE_RE.match(os.path.basename(name))
Beispiel #21
0
def cmdwin(matcher_info):
    name = buffer_name(matcher_info)
    return name and os.path.basename(name) == b'[Command Line]'
Beispiel #22
0
def ctrlp(matcher_info):
    name = buffer_name(matcher_info)
    return name and os.path.basename(name) == b'ControlP'
Beispiel #23
0
def commandt(matcher_info):
	name = buffer_name(matcher_info)
	return name and os.path.basename(name) == b'GoToFile'
Beispiel #24
0
def evernote(matcher_info):
    name = buffer_name(matcher_info)
    return name and EVERNOTE_RE.match(os.path.basename(name))
Beispiel #25
0
def ctrlp(matcher_info):
	name = buffer_name(matcher_info)
	return name and os.path.basename(name) == b'ControlP'
Beispiel #26
0
def commandt(matcher_info):
    name = buffer_name(matcher_info)
    return name and os.path.basename(name) == b'GoToFile'
Beispiel #27
0
def commandt(matcher_info):
    name = buffer_name(matcher_info)
    return (
        vim_getbufoption(matcher_info, 'filetype') == 'command-t'
        or (name and os.path.basename(name) == b'GoToFile')
    )
Beispiel #28
0
def commandt(matcher_info):
	name = buffer_name(matcher_info)
	return (
		vim_getbufoption(matcher_info, 'filetype') == 'command-t'
		or (name and os.path.basename(name) == b'GoToFile')
	)
Beispiel #29
0
def gundo(matcher_info):
	name = buffer_name(matcher_info)
	return name and os.path.basename(name) == b'__Gundo__'
Beispiel #30
0
def evernote_explorer(matcher_info):
    name = buffer_name(matcher_info)
    return name and EVERNOTE_EXPLORER_RE.match(os.path.basename(name))
Beispiel #31
0
def tagbar(matcher_info):
	name = buffer_name(matcher_info)
	return name and os.path.basename(name) == b'__Tagbar__'
Beispiel #32
0
def gundo(matcher_info):
    name = buffer_name(matcher_info)
    return name and os.path.basename(name) == b'__Gundo__'
Beispiel #33
0
def nerdtree(matcher_info):
    name = buffer_name(matcher_info)
    return name and NERD_TREE_RE.match(os.path.basename(name))
Beispiel #34
0
def geeknote(matcher_info):
	name = buffer_name(matcher_info)
	return name and GEEKNOTE_RE.match(os.path.basename(name))
Beispiel #35
0
def cmdwin(matcher_info):
	name = buffer_name(matcher_info)
	return name and os.path.basename(name) == b'[Command Line]'
Beispiel #36
0
 def get_directory(segment_info):
     if vim_getbufoption(segment_info, 'buftype'):
         return None
     return buffer_name(segment_info)
Beispiel #37
0
def geeknote_explorer(matcher_info):
	name = buffer_name(matcher_info)
	return name and GEEKNOTE_EXPLORER_RE.match(os.path.basename(name))