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

Modified: sublimegdb.py: expand_path #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sublimegdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,21 @@ def expand_path(value, window):
]
view = window.active_view()
file_name = view.file_name();
sublime_vars = window.extract_variables()
# replace variable with values
if file_name:
value = re.sub(r'\${file}', lambda m: file_name, value)
value = re.sub(r'\${file_base_name}', lambda m: os.path.splitext(os.path.basename(file_name))[0], value)
if os.getenv("HOME"):
value = re.sub(r'\${home}', re.escape(os.getenv('HOME')), value)
value = re.sub(r'\${env:(?P<variable>.*)}', lambda m: os.getenv(m.group('variable')), value)
n=1
while n:
value,n = re.subn(r'\${env:(?P<variable>[^$]*?)}', lambda m: os.getenv(m.group('variable')) if os.getenv(m.group('variable')) else sublime_vars[m.group('variable')], value)
# search in projekt for path and get folder from path
value = re.sub(r'\${project_path:(?P<file>[^}]+)}', lambda m: len(get_existing_files(m)) > 0 and get_existing_files(m)[0] or m.group('file'), value)
value = re.sub(r'\${folder:(?P<file>.*)}', lambda m: os.path.dirname(m.group('file')), value)
value = re.sub(r'\${project_path:(?P<file>.*?)}', lambda m: len(get_existing_files(m)) > 0 and get_existing_files(m)[0] or m.group('file'), value)
n=1
while n:
value,n = re.subn(r'\${folder:(?P<file>.*?)}', lambda m: os.path.dirname(m.group('file')), value)
value = value.replace('\\', os.sep)
value = value.replace('/', os.sep)

Expand Down