├── .gitignore ├── tests ├── __init__.py ├── requirements.txt ├── docker │ ├── centos-7.Dockerfile │ ├── debian-10.Dockerfile │ ├── debian-9.Dockerfile │ ├── debian-11.Dockerfile │ ├── debian-12.Dockerfile │ ├── scop.Dockerfile │ ├── README.md │ └── bash-3.2.Dockerfile ├── test_case_insensitive.py ├── test_debug.py ├── test_issue23.py ├── test_scop_completion.py ├── logging.py ├── test_special_characters.py ├── test_tilde.py ├── conftest.py ├── test_simple.py ├── test_issue10.py ├── test_tabkey.py ├── test_clean_env.py ├── test_release.py ├── README.md └── common.py ├── .shellcheckrc ├── .ci ├── cirrus-macos.yml.j2 └── cirrus-freebsd.yml.j2 ├── Makefile ├── .github └── workflows │ ├── docker.yml │ └── test.yml ├── CHANGELOG.md ├── README.md ├── LICENSE ├── bash_completion └── docs └── demo.asciicast /.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile.venv 2 | /.venv 3 | *.pyc 4 | /.hypothesis 5 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Automated tests for bash-complete-partial-path 3 | ''' 4 | -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- 1 | # Ignore unreachable code chunks (_filedir_original) 2 | disable=SC2317 3 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pexpect 2 | pytest 3 | hypothesis 4 | 5 | # Compatibility with older Python versions 6 | typing; python_version < '3.5' 7 | -------------------------------------------------------------------------------- /tests/docker/centos-7.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | 3 | RUN yum -y --setopt=tsflags=nodocs update && \ 4 | yum -y --setopt=tsflags=nodocs install \ 5 | make \ 6 | curl \ 7 | python3 \ 8 | bash \ 9 | sed \ 10 | && \ 11 | yum clean all 12 | -------------------------------------------------------------------------------- /tests/test_case_insensitive.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.mark.parametrize('path', ['u/s/a','us/s']) 4 | def test_case_insensitive(bash, path): 5 | '''Test case insensitive path expansion''' 6 | ls = 'ls %s' 7 | assert bash.complete(ls % path) == bash.complete(ls % path.upper()) 8 | -------------------------------------------------------------------------------- /tests/test_debug.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Interactive debugging in test environment 3 | ''' 4 | import os 5 | import pytest 6 | 7 | 8 | @pytest.mark.skipif('BCPP_TEST_DEBUG' not in os.environ, reason='skipping interactive pdb session') 9 | def test_debug(bash): 10 | import pdb; pdb.set_trace() 11 | -------------------------------------------------------------------------------- /tests/docker/debian-10.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:10-slim 2 | 3 | RUN \ 4 | apt-get update && \ 5 | apt-get install -y \ 6 | make \ 7 | curl \ 8 | python3 \ 9 | python3-venv \ 10 | bash \ 11 | sed \ 12 | && \ 13 | apt-get clean 14 | -------------------------------------------------------------------------------- /tests/docker/debian-9.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:9-slim 2 | 3 | RUN \ 4 | apt-get update && \ 5 | apt-get install -y \ 6 | make \ 7 | curl \ 8 | python3 \ 9 | python3-venv \ 10 | bash \ 11 | sed \ 12 | && \ 13 | apt-get clean 14 | -------------------------------------------------------------------------------- /tests/docker/debian-11.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye-slim 2 | 3 | RUN \ 4 | apt-get update && \ 5 | apt-get install -y \ 6 | make \ 7 | curl \ 8 | python3 \ 9 | python3-venv \ 10 | bash \ 11 | sed \ 12 | && \ 13 | apt-get clean 14 | -------------------------------------------------------------------------------- /tests/docker/debian-12.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bookworm-slim 2 | 3 | RUN \ 4 | apt-get update && \ 5 | apt-get install -y \ 6 | make \ 7 | curl \ 8 | python3 \ 9 | python3-venv \ 10 | bash \ 11 | sed \ 12 | && \ 13 | apt-get clean 14 | -------------------------------------------------------------------------------- /tests/docker/scop.Dockerfile: -------------------------------------------------------------------------------- 1 | # Test environment that provides https://github.com/scop/bash-completion 2 | 3 | FROM ghcr.io/sio/bash-complete-partial-path:debian-12 4 | 5 | RUN \ 6 | apt-get install -y bash-completion && \ 7 | apt-get clean 8 | 9 | ENV BCPP_TEST_SCOP_COMPLETION /etc/bash_completion 10 | -------------------------------------------------------------------------------- /tests/docker/README.md: -------------------------------------------------------------------------------- 1 | # Environments for bash-complete-partial-path tests 2 | 3 | Docker environments for automated testing of [bash-complete-partial-path][bcpp]. 4 | 5 | - Images are published at GitHub Container Registry: [`ghcr.io/sio/bash-complete-partial-path`][registry] 6 | - Docker tags correspond to [`*.Dockerfile`][dockerfiles] filenames 7 | - Automatic builds are triggered by pushing to `master` or to `dockerhub` 8 | (if any of Dockerfiles were modified) 9 | - Containers are also rebuilt automatically on a regular schedule 10 | 11 | [bcpp]: https://github.com/sio/bash-complete-partial-path 12 | [registry]: https://github.com/users/sio/packages/container/bash-complete-partial-path/versions 13 | [dockerfiles]: https://github.com/sio/bash-complete-partial-path/tree/master/tests/docker 14 | -------------------------------------------------------------------------------- /.ci/cirrus-macos.yml.j2: -------------------------------------------------------------------------------- 1 | task: 2 | name: 'ci/cirrusci: test-macos' 3 | macos_instance: 4 | image: ghcr.io/cirruslabs/macos-ventura-base:latest 5 | env: 6 | SED: gsed 7 | PIP_CACHE_DIR: $CIRRUS_WORKING_DIR/cache/pip 8 | # VENVDIR should not be cached: Cirrus CI drops bin/python for some reason when saving cache 9 | CLONE_SHA: "{{ GITHUB_SHA }}" 10 | CLONE_URL: "{{ GITHUB_SERVER_URL }}/{{ GITHUB_REPOSITORY }}.git" 11 | clone_script: 12 | - git clone "$CLONE_URL" . 13 | - git reset --hard "$CLONE_SHA" 14 | venv_cache: 15 | folder: cache 16 | fingerprint_script: 17 | - echo "Cache ID: macOS Big Sur" 18 | - cat tests/requirements.txt 19 | before_script: 20 | - brew install coreutils gnu-sed bash make 21 | test_script: 22 | - gmake test 23 | -------------------------------------------------------------------------------- /tests/test_issue23.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Edge case for directory names containing whitespace 3 | 4 | https://github.com/sio/bash-complete-partial-path/issues/23 5 | https://asciinema.org/a/549127 6 | ''' 7 | 8 | import pytest 9 | 10 | from pathlib import Path 11 | 12 | @pytest.fixture(scope='class') 13 | def custom_bash(bash): 14 | root = Path(bash.tmpdir) 15 | dirs = [ 16 | root / "abc" / "def ghi", 17 | root / "abc" / "djkl", 18 | ] 19 | for d in dirs: 20 | d.mkdir(parents=True) 21 | yield bash 22 | 23 | class TestIssue23: 24 | def test_happy_path(self, custom_bash): 25 | want = {'abc/def ghi', 'abc/djkl'} 26 | got = set(custom_bash.complete('cd abc/d')) 27 | assert got == want 28 | 29 | def test_tricky_path(self, custom_bash): 30 | want = {'abc/def ghi', 'abc/djkl'} 31 | got = set(custom_bash.complete('cd abc/')) 32 | assert got == want 33 | -------------------------------------------------------------------------------- /tests/test_scop_completion.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pytest 3 | 4 | from tests.conftest import STARTUP 5 | 6 | 7 | ENV_SCOP = 'BCPP_TEST_SCOP_COMPLETION' 8 | 9 | 10 | @pytest.mark.skipif(ENV_SCOP not in os.environ, reason='environment variable not set: %s' % ENV_SCOP) 11 | def test_scop_completion(bash): 12 | '''Test compatibility with main bash-completion package''' 13 | bash.execute('exec bash --norc --noprofile') 14 | 15 | declare = bash.execute('declare -F') 16 | assert '_filedir' not in declare 17 | assert '_bcpp_filedir' not in declare 18 | 19 | bash.execute('source "${}"'.format(ENV_SCOP)) 20 | for cmd in STARTUP: 21 | bash.execute(cmd) 22 | 23 | declare = bash.execute('declare -F') 24 | assert '_filedir' in declare 25 | assert '_bcpp_filedir' in declare 26 | 27 | completion = bash.complete('ls u/s/a') 28 | assert len(completion) > 1 29 | assert 'usr/share/applications' in completion 30 | -------------------------------------------------------------------------------- /.ci/cirrus-freebsd.yml.j2: -------------------------------------------------------------------------------- 1 | task: 2 | name: 'ci/cirrusci: test-freebsd' 3 | freebsd_instance: 4 | image_family: freebsd-14-0 # https://cirrus-ci.org/guide/FreeBSD/ 5 | env: 6 | SED: gsed 7 | PIP_CACHE_DIR: $CIRRUS_WORKING_DIR/cache/pip 8 | # VENVDIR should not be cached: Cirrus CI drops bin/python for some reason when saving cache 9 | CLONE_SHA: "{{ GITHUB_SHA }}" 10 | CLONE_URL: "{{ GITHUB_SERVER_URL }}/{{ GITHUB_REPOSITORY }}.git" 11 | before_script: 12 | - pkg update 13 | - pkg install -y 14 | python3 15 | gmake 16 | curl 17 | coreutils 18 | bash 19 | gsed 20 | git 21 | - ln -sf /usr/local/bin/gsha256sum /sbin/sha256sum 22 | - which sha256sum 23 | - sha256sum --version 24 | - pw useradd -n testuser -m -w random 25 | clone_script: 26 | - git clone "$CLONE_URL" . 27 | - git reset --hard "$CLONE_SHA" 28 | venv_cache: 29 | folder: cache 30 | fingerprint_script: 31 | - echo "Cache ID: 1" 32 | - cat tests/requirements.txt 33 | test_script: 34 | - chown -R testuser . 35 | - su testuser -c 'gmake test' 36 | -------------------------------------------------------------------------------- /tests/logging.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Logging setup for bcpp tests 3 | ''' 4 | 5 | import logging 6 | import os 7 | 8 | 9 | class ShyLogHandler(logging.StreamHandler): 10 | '''Emit messages only if root logger has no other handlers''' 11 | root = logging.getLogger() 12 | def emit(self, record): 13 | if not self.root.hasHandlers(): 14 | super().emit(record) 15 | 16 | 17 | def setup(): 18 | log = logging.getLogger('bcpp_tests') 19 | if getattr(log, 'initialized', False): 20 | return log 21 | 22 | log_file = os.environ.get('BCPP_TEST_LOG_FILE') 23 | log_stdout = os.environ.get('BCPP_TEST_LOG_STDOUT') 24 | 25 | log.level = logging.DEBUG 26 | 27 | if log_file: 28 | handler = logging.FileHandler(log_file, encoding='utf-8') 29 | handler.level = logging.DEBUG 30 | handler.formatter = logging.Formatter('%(asctime)s - %(message)s') 31 | log.addHandler(handler) 32 | 33 | if log_stdout: 34 | handler = ShyLogHandler() 35 | handler.level = logging.DEBUG 36 | log.addHandler(handler) 37 | 38 | log.initialized = True 39 | return log 40 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PYTEST_ARGS?=-p no:cacheprovider 2 | REQUIREMENTS_TXT=tests/requirements.txt 3 | SED?=sed 4 | 5 | 6 | CLEANUP_FILES=Makefile.venv 7 | CLEANUP_DIRS=.hypothesis 8 | 9 | 10 | test: deps venv 11 | $(VENV)/pytest $(PYTEST_ARGS) 12 | 13 | 14 | lint: 15 | @shellcheck --version 16 | shellcheck --color=always bash_completion 17 | 18 | 19 | clean: clean-venv 20 | -$(RM) $(CLEANUP_FILES) 21 | -$(RM) -r $(CLEANUP_DIRS) 22 | 23 | 24 | .PHONY: deps 25 | deps: 26 | $(MAKE) --version 27 | $(PY) --version 28 | $(SED) --version 29 | bash --version 30 | 31 | 32 | -include Makefile.venv 33 | Makefile.venv: 34 | curl \ 35 | -o Makefile.fetched \ 36 | -L "https://github.com/sio/Makefile.venv/raw/v2020.08.14/Makefile.venv" 37 | echo "5afbcf51a82f629cd65ff23185acde90ebe4dec889ef80bbdc12562fbd0b2611 *Makefile.fetched" \ 38 | | sha256sum --check - \ 39 | && mv Makefile.fetched Makefile.venv 40 | 41 | 42 | # Override default venv packages for older Python versions 43 | # https://github.com/pypa/get-pip/pull/46/files 44 | ifeq (True,$(shell $(PY) -c "import sys; print(sys.version_info < (3,5))")) 45 | $(VENV): 46 | $(PY) -m venv $(VENVDIR) 47 | $(VENV)/python -m pip install --upgrade "pip<19.2" "setuptools<44.0" "wheel<0.34" 48 | endif 49 | -------------------------------------------------------------------------------- /tests/test_special_characters.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test enhanced completion for paths with special chars 3 | ''' 4 | 5 | from pathlib import Path 6 | import pytest 7 | 8 | 9 | class TestSpecialCharacters: 10 | '''All subtests will use the same bash session''' 11 | 12 | @pytest.mark.parametrize( 13 | 'special,shortcut', 14 | [ 15 | ('usr/share/a file with spaces', 'u/s/a'), 16 | ('some/very/weird &file!', 's/v/w'), 17 | ] 18 | ) 19 | @pytest.mark.parametrize('quotes', ['', '"', "'"]) 20 | def test_special_chars(self, bash, special, shortcut, quotes): 21 | '''Test special character handling''' 22 | special_path = Path(bash.tmpdir) / special 23 | parent = special_path.parents[0] 24 | if not parent.exists(): 25 | parent.mkdir(parents=True) # exist_ok is not supported in Python 3.4 26 | special_path.touch() 27 | 28 | command = 'ls {}{}'.format(quotes, shortcut) 29 | output = bash.complete(command) 30 | 31 | if len(output) == 1: 32 | assert quotes + special in output.selected 33 | if quotes: # shlex fails when completion happens in open quotes 34 | output = str(output) 35 | assert special in output 36 | -------------------------------------------------------------------------------- /tests/test_tilde.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Tests for tilde expansion 3 | https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html 4 | ''' 5 | 6 | 7 | from getpass import getuser 8 | from pathlib import Path 9 | from tempfile import TemporaryDirectory 10 | import os.path 11 | 12 | import pytest 13 | 14 | 15 | @pytest.mark.parametrize('tilde', ['~', '~{}'.format(getuser())]) 16 | def test_home(bash, tilde): 17 | '''~, ~username expansion''' 18 | home = Path(os.path.expanduser(tilde)) # Path.home() is unavailable in Python 3.4 19 | subdir = Path('foo/bar/baz') 20 | with TemporaryDirectory(prefix='.bcpp-test-', dir=str(home)) as tmpdir: 21 | testdir = home / tmpdir / subdir 22 | testdir.mkdir(parents=True) 23 | assert testdir.exists() 24 | command = 'ls {}/{}/f/b/b'.format(tilde, Path(tmpdir).relative_to(home)) 25 | completed = bash.complete(command) 26 | assert completed, 'no completion for: %s' % command 27 | assert completed == 'ls {}'.format(testdir) 28 | 29 | 30 | def test_pushd(bash): 31 | '''~1, ~2 expansion''' 32 | bash.execute('pushd usr') 33 | directory = Path('usr/share/applications') 34 | assert bash.complete('ls ~1/u/s/app') == 'ls {}'.format((bash.tmpdir / directory).resolve()) 35 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | # Build Docker images and push them to GitHub Container Registry 2 | 3 | name: ci/ghcr 4 | 5 | on: 6 | push: 7 | branches: 8 | - dockerhub 9 | - master 10 | paths: 11 | - tests/docker/*.Dockerfile 12 | schedule: 13 | - cron: '45 3 4,14,24 * *' 14 | 15 | jobs: 16 | docker-build: 17 | name: build-${{ matrix.tag }} 18 | runs-on: ubuntu-latest 19 | strategy: 20 | matrix: 21 | tag: 22 | - bash-3.2 23 | - centos-7 24 | - debian-10 25 | - debian-11 26 | - debian-12 27 | - scop 28 | env: 29 | DOCKER_TAG: ${{ matrix.tag }} 30 | DOCKER_REPO: ghcr.io/sio/bash-complete-partial-path 31 | DOCKER_USER: sio 32 | DOCKER_REGISTRY: ghcr.io 33 | steps: 34 | - uses: actions/checkout@v3 35 | 36 | - name: Build image and push it to registry 37 | run: | 38 | export DOCKERFILE=tests/docker/$DOCKER_TAG.Dockerfile 39 | echo ${{ secrets.CONTAINER_REGISTRY_PERSONAL_ACCESS_TOKEN }} \ 40 | | docker login -u $DOCKER_USER --password-stdin $DOCKER_REGISTRY 41 | docker build --pull --tag $DOCKER_REPO:$DOCKER_TAG - < $DOCKERFILE 42 | docker push $DOCKER_REPO:$DOCKER_TAG 43 | -------------------------------------------------------------------------------- /tests/docker/bash-3.2.Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Build bash from source 3 | # 4 | 5 | FROM debian:10-slim AS builder 6 | 7 | RUN \ 8 | apt-get update && \ 9 | apt-get install -y \ 10 | autoconf \ 11 | autotools-dev \ 12 | bison \ 13 | curl \ 14 | gcc \ 15 | gettext \ 16 | libncurses5-dev \ 17 | make \ 18 | && \ 19 | apt-get clean 20 | 21 | ENV BASH_SRC_VERSION 3.2.57 22 | ENV BASH_SRC_SHA256 3fa9daf85ebf35068f090ce51283ddeeb3c75eb5bc70b1a4a7cb05868bfe06a4 23 | ENV BASH_SRC_URL http://ftpmirror.gnu.org/bash/bash-${BASH_SRC_VERSION}.tar.gz 24 | RUN \ 25 | mkdir /bash-build && \ 26 | cd /bash-build && \ 27 | curl -L "$BASH_SRC_URL" -o bash-source.tar.gz && \ 28 | echo "$BASH_SRC_SHA256 *bash-source.tar.gz" | sha256sum --check - && \ 29 | tar axf bash-source.tar.gz && \ 30 | cd "bash-$BASH_SRC_VERSION"* && \ 31 | ./configure --prefix=/bash && \ 32 | make && \ 33 | make install 34 | 35 | 36 | # 37 | # Compose environment for automated tests 38 | # 39 | 40 | FROM debian:10-slim 41 | 42 | RUN \ 43 | apt-get update && \ 44 | apt-get install -y \ 45 | make \ 46 | curl \ 47 | python3 \ 48 | python3-venv \ 49 | bash \ 50 | sed \ 51 | && \ 52 | apt-get clean 53 | COPY --from=builder /bash /bash 54 | ENV PATH /bash/bin:${PATH} 55 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Release history for bash-complete-partial-path 2 | 3 | ## v1.0.0 (2019-12-04) 4 | 5 | The project has been around for a long time, but no formal releases were 6 | made. From now on the project will follow semantic versioning convention. 7 | 8 | Current release of bash-complete-partial-path is considered stable and all users 9 | are recommended to upgrade to this version. 10 | 11 | All desired functionality is implemented and has been in use for more than a 12 | year on several platforms. Automated tests and CI were added recently to 13 | detect regressions and to monitor compatibility with all supported platforms. 14 | 15 | Changes introduced over the past year: 16 | 17 | - Fixed behavior mismatch with default completion when completing simple paths 18 | (#10) 19 | - Fixed compatibility issues with older bash (4.2) and sed (4.2.2) - still in 20 | use in RedHat Linux 7.7 21 | - Ignore any aliases set up by user when calling core system commands 22 | 23 | 24 | ## Untagged release (2018-09-20) 25 | 26 | A lot of development happened in the first months: 27 | 28 | - Sourcing the completion script is now free of side effects. All 29 | configuration happens via explicit calls to `_bcpp` manager function 30 | - macOS is now supported 31 | - Shift+Tab can now be used to go back through completion variants 32 | - Environment variables are correctly expanded 33 | - Rare occurences of garbage output are fixed 34 | 35 | 36 | ## Untagged release (2018-07-15) 37 | 38 | First published version of bash-complete-partial-path was able to correctly 39 | complete partial paths, non-Linux systems were not yet supported though. 40 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Shared fixtures for completion testing 3 | ''' 4 | 5 | from pathlib import Path 6 | from tempfile import TemporaryDirectory 7 | import pytest 8 | 9 | from tests.common import BashSession 10 | import tests.logging 11 | 12 | 13 | BCPP = 'bash_completion' # relative path from repo's top level 14 | 15 | STARTUP = [ 16 | 'source "{}"'.format(Path(BCPP).resolve()), 17 | '_bcpp --defaults', 18 | ] 19 | FILETREE = { 20 | 'files': [ 21 | 'usr/somefile', 22 | 'usr/share/afile', 23 | ], 24 | 'dirs': [ 25 | 'usr/share/applications', 26 | 'usr/share/another', 27 | 'usr/share/anything', 28 | ], 29 | } 30 | 31 | 32 | @pytest.fixture(scope='class') 33 | def bash(log) -> BashSession: 34 | ''' 35 | Fixture for automated tests. 36 | 37 | Provides BashSession object initialized in a temporary directory with bcpp 38 | preloaded. Temp directory is cleaned up automatically 39 | ''' 40 | with TemporaryDirectory(prefix='bcpp_test_') as tmpdir: 41 | log.debug('Creating bash fixture: %s', tmpdir) 42 | shell = BashSession( 43 | startup=STARTUP, 44 | cwd=tmpdir, 45 | ) 46 | shell.tmpdir = tmpdir 47 | 48 | root = Path(tmpdir) 49 | for dirname in FILETREE['dirs']: 50 | (root / dirname).mkdir(parents=True) 51 | for filename in FILETREE['files']: 52 | (root / filename).touch() 53 | 54 | yield shell 55 | log.debug('Destroying bash fixture: %s', tmpdir) 56 | 57 | 58 | @pytest.fixture(scope='session') 59 | def log(): 60 | return tests.logging.setup() 61 | -------------------------------------------------------------------------------- /tests/test_simple.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Simple completion cases for file and directory paths 3 | ''' 4 | 5 | import pytest 6 | 7 | 8 | class TestPathCompletion: 9 | '''All tests in this class will run within the same instance of bash''' 10 | 11 | @pytest.mark.parametrize( 12 | 'command,completion', 13 | ( 14 | # Default completer 15 | ('ls us', 'r'), 16 | ('cd us', 'r'), 17 | ('ls usr/sha', 're'), 18 | ('ls ', 'usr/'), 19 | ('cd usr/', 'share'), 20 | 21 | # Partial path completer 22 | ('ls u/s/app', 'ls usr/share/applications'), 23 | ('cd u/s', 'cd usr/share'), 24 | ) 25 | ) 26 | def test_one_result(self, bash, command, completion): 27 | '''Complete unambiguos paths''' 28 | assert bash.complete(command) == completion 29 | 30 | 31 | @pytest.mark.parametrize( 32 | 'command,variants', 33 | ( 34 | # Default completer 35 | ('ls usr/s', ['usr/share', 'usr/somefile']), 36 | ('ls usr/', ['share/', 'somefile']), 37 | ('cd usr/share/a', ['usr/share/another', 'usr/share/anything', 'usr/share/applications']), 38 | ('cd usr/share/', ['usr/share/another', 'usr/share/anything', 'usr/share/applications']), 39 | 40 | # Partial path completer 41 | ('ls u/s/a', ['usr/share/afile', 'usr/share/another', 'usr/share/anything', 'usr/share/applications']), 42 | ('cd u/s/a', ['usr/share/another', 'usr/share/anything', 'usr/share/applications']), 43 | ) 44 | ) 45 | def test_many_results(self, bash, command, variants): 46 | '''Complete ambiguous paths''' 47 | completed = bash.complete(command) 48 | assert completed, 'empty completion' 49 | assert set(variants) == set(completed) 50 | -------------------------------------------------------------------------------- /tests/test_issue10.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Tests for issue #10 3 | https://github.com/sio/bash-complete-partial-path/issues/10 4 | ''' 5 | 6 | 7 | import pytest 8 | 9 | from tests.conftest import FILETREE, STARTUP 10 | 11 | 12 | class Test_Issue10: 13 | '''Share bash instance between the following tests''' 14 | 15 | DIR = 'usr/share' 16 | 17 | @pytest.mark.parametrize('command', ['cd', 'ls']) 18 | def test_single(self, bash, command): 19 | '''Check that single tab adds trailing slash to directory name''' 20 | completed = bash.complete('{} {}'.format(command, self.DIR)) 21 | assert completed == '/' 22 | 23 | @pytest.mark.parametrize('command', ['cd', 'ls']) 24 | def test_double(self, bash, command): 25 | '''Check that double tab lists directory contents''' 26 | completed = bash.complete('{} {}'.format(command, self.DIR), tabs=2) 27 | variants = set(completed) 28 | files = set(x for x in FILETREE['files'] if x.startswith(self.DIR)) 29 | dirs = set(x for x in FILETREE['dirs'] if x.startswith(self.DIR)) 30 | 31 | if command == 'ls': 32 | dirs = set(d + '/' for d in dirs) 33 | dirs.add('/') 34 | correct = set(x.replace(self.DIR + '/', '', 1) for x in files.union(dirs)) 35 | assert variants == correct 36 | elif command == 'cd': 37 | dirs.add('/') 38 | assert variants == dirs 39 | else: 40 | assert False, 'unsupported command: {}'.format(command) 41 | 42 | 43 | def test_aliases(bash): 44 | '''Do not use aliases for dependencies''' 45 | message = 'ALIASES MUST NOT BE INVOKED' 46 | bash.execute('alias rm="echo {}"'.format(message)) 47 | for command in STARTUP: # reinitialize bash-complete-partial-path 48 | bash.execute(command) 49 | assert bash.execute('rm --help') == message + ' --help' 50 | assert bash.complete('ls us') == 'r' 51 | -------------------------------------------------------------------------------- /tests/test_tabkey.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test keyboard shortcuts 3 | ''' 4 | 5 | 6 | from hypothesis import ( 7 | given, 8 | settings, 9 | strategies as st, 10 | ) 11 | 12 | class TestShortcuts: 13 | 14 | def test_tab_cycles(self, bash): 15 | '''Repeated Tab presses should loop though available completions''' 16 | command = 'ls u/s/a' 17 | cycle_length = len(bash.complete(command)) + 1 18 | completions = {n: bash.complete(command, tabs=n) for n in range(1, cycle_length)} 19 | for tabs, completion in completions.items(): 20 | next_cycle = bash.complete(command, tabs=tabs + cycle_length) 21 | assert completion == next_cycle, 'tabs: {}, old: {}, new: {}'.format( 22 | tabs, completion.selected, next_cycle.selected) 23 | 24 | @settings(deadline=None, max_examples=10) 25 | @given(forward = st.integers(min_value=1, max_value=15), 26 | backward = st.integers(min_value=1, max_value=15)) 27 | def test_shift_tab(self, bash, log, forward, backward): 28 | '''Shift-Tab cycles back''' 29 | command = 'ls u/s/a' 30 | cycle_length = len(bash.complete(command)) + 1 31 | 32 | TAB = '\t' 33 | SHIFT_TAB = '\x1b\x5b\x5a' # use 'showkey -a' on any Linux machine 34 | # to see ASCII codes corresponding to keypresses 35 | 36 | tabs_forward = TAB * ((forward - backward) % cycle_length) 37 | if not tabs_forward: # in case we cycle back to the original command 38 | tabs_forward = TAB + SHIFT_TAB 39 | tabs_forward_and_back = TAB * forward + SHIFT_TAB * backward 40 | log.debug( 41 | '[%s/%s] tab sequences: forward=%r, forward and back=%r', 42 | forward, 43 | backward, 44 | tabs_forward, 45 | tabs_forward_and_back 46 | ) 47 | assert bash.complete(command, custom_tabs=tabs_forward) == \ 48 | bash.complete(command, custom_tabs=tabs_forward_and_back) 49 | -------------------------------------------------------------------------------- /tests/test_clean_env.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Check that environment stays clean after importing bcpp 3 | ''' 4 | 5 | import difflib 6 | import re 7 | from tests.common import BashSession 8 | from tests.conftest import STARTUP 9 | 10 | 11 | def grep(needle, haystack): 12 | results = [] 13 | query = re.finditer( 14 | r'^(.*%s.*)$' % re.escape(needle), 15 | haystack, 16 | re.MULTILINE 17 | ) 18 | for match in query: 19 | results.append(match.group(1)) 20 | return results 21 | 22 | 23 | def test_env_clean(): 24 | ''' 25 | Compare shell environments before and after invoking bcpp 26 | ''' 27 | cmd_show_env = r"(declare -p; declare -F)|grep -E '^declare\b'|sort" 28 | declare = re.compile(r'^declare\b(?:\s+\-\S+)+\s+') 29 | env_item = re.compile(declare.pattern + r'(\w+)') 30 | 31 | ignore_items = { # Changes to variables from this set are ignored 32 | 'BASHOPTS', # - meant to be modified by _bcpp 33 | 'BASH_ARGC', # - volatile, modified almost always 34 | 'BASH_ARGV', # - volatile, modified almost always 35 | 'PIPESTATUS', # - volatile: https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html 36 | '_', # - volatile: https://askubuntu.com/questions/1198935 37 | } 38 | 39 | bash = BashSession() 40 | before = bash.execute(cmd_show_env) 41 | for cmd in STARTUP: 42 | bash.execute(cmd) 43 | bash.complete('cd /u') 44 | bash.complete('ls /') 45 | after = bash.execute(cmd_show_env) 46 | 47 | for line in difflib.Differ().compare(before.splitlines(), after.splitlines()): 48 | content = line[1:].strip() 49 | 50 | match = env_item.match(content) 51 | if match: 52 | item = match.group(1) 53 | else: 54 | item = content 55 | if item in ignore_items \ 56 | or not content: 57 | continue 58 | 59 | error_msg = '' 60 | if line.startswith('-'): 61 | error_msg = 'Item missing from environment:\n{line}' 62 | if line.startswith('+'): 63 | if not item.lower().startswith('_bcpp'): 64 | error_msg = 'Extra item in environment:\n{line}' 65 | if error_msg: 66 | error_extra = [ 67 | '', 68 | 'Environment before:\n{}'.format('\n'.join(grep(item, before))), 69 | 'Environment after:\n{}'.format('\n'.join(grep(item, after))), 70 | ] 71 | raise AssertionError(error_msg.format(line=line) + '\n'.join(error_extra)) 72 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: ci/github 2 | on: 3 | push: 4 | paths-ignore: 5 | - '**.md' 6 | - '.git*' 7 | pull_request: 8 | workflow_dispatch: 9 | schedule: 10 | - cron: '45 3 5,15,25 * *' 11 | 12 | 13 | jobs: 14 | test-linux: 15 | runs-on: ubuntu-latest 16 | name: test-${{ matrix.image }} 17 | container: ghcr.io/sio/bash-complete-partial-path:${{ matrix.image }} 18 | strategy: 19 | matrix: 20 | image: 21 | - centos-7 22 | - debian-9 23 | - debian-10 24 | - debian-11 25 | - debian-12 26 | - scop 27 | env: 28 | PIP_CACHE_DIR: cache/pip 29 | steps: 30 | - uses: actions/checkout@v3 31 | - uses: actions/cache@v3 32 | with: 33 | path: cache 34 | key: cache-v1-${{ runner.os }}-${{ matrix.image }}-${{ hashFiles('tests/requirements.txt') }} 35 | - run: make test 36 | 37 | test-other-os: 38 | name: test-${{ matrix.os }} 39 | runs-on: ubuntu-latest 40 | container: potyarkin/cirrus-run 41 | strategy: 42 | matrix: 43 | os: 44 | - freebsd 45 | - macos 46 | env: 47 | CIRRUS_API_TOKEN: ${{ secrets.CIRRUS_API_TOKEN }} 48 | CIRRUS_GITHUB_REPO: ${{ secrets.CIRRUS_GITHUB_REPO }} 49 | CIRRUS_SHOW_BUILD_LOG: always 50 | steps: 51 | - uses: actions/checkout@v3 52 | - run: cirrus-run .ci/cirrus-${{ matrix.os }}.yml.j2 53 | 54 | test-msys2: 55 | runs-on: windows-latest 56 | env: 57 | PIP_CACHE_DIR: cache/pip 58 | defaults: 59 | run: 60 | shell: C:\msys64\usr\bin\bash.exe -xeuo pipefail {0} 61 | steps: 62 | - uses: actions/checkout@v3 63 | - uses: actions/cache@v3 64 | with: 65 | path: cache 66 | key: cache-v1-${{ runner.os }}-msys2-${{ hashFiles('tests/requirements.txt') }} 67 | 68 | - name: Upgrade Msys2 environment 69 | run: |- 70 | exec pacman --noconfirm -Syu 71 | env: 72 | PATH: '/usr/local/bin:/usr/bin:/bin' 73 | 74 | - name: Install dependencies 75 | run: |- 76 | exec pacman --noconfirm -Sy make python3 libopenssl curl libcurl 77 | env: 78 | PATH: '/usr/local/bin:/usr/bin:/bin' 79 | 80 | - name: make test 81 | run: |- 82 | make test 83 | env: 84 | PATH: '/usr/local/bin:/usr/bin:/bin' 85 | 86 | shellcheck: 87 | runs-on: ubuntu-latest 88 | name: shellcheck 89 | container: koalaman/shellcheck-alpine 90 | steps: 91 | - uses: actions/checkout@v3 92 | - run: apk update; apk add make 93 | - run: make lint 94 | -------------------------------------------------------------------------------- /tests/test_release.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Sanity checks for new release 3 | ''' 4 | 5 | from shutil import which 6 | from subprocess import Popen, PIPE 7 | import re 8 | 9 | import pytest 10 | 11 | 12 | BCPP = 'bash_completion' 13 | CHANGELOG = 'CHANGELOG.md' 14 | VERSION = re.compile(r'\b(v\d+\.\d+\.\d(?:-[\w\d]+|\b))') # semver 15 | 16 | 17 | skipif_no_git = pytest.mark.skipif(not which('git'), reason='git not found in $PATH') 18 | 19 | 20 | def skip_development_versions(message=None): 21 | '''Skip some tests on development versions''' 22 | app_version = read_version(BCPP, lines=5) 23 | if app_version.endswith('-dev'): 24 | pytest.skip(message or 'skip checks for -dev versions') 25 | 26 | 27 | def run(command, **ka): 28 | '''Backwards compatible subprocess runner''' 29 | process = Popen(command, **ka) 30 | exit_code = process.wait() 31 | output = process.stdout.read().decode().strip() 32 | if exit_code: 33 | raise RuntimeError('command returned {}: {}'.format(exit_code, ' '.join(command))) 34 | return output 35 | 36 | 37 | def read_version(filename, lines=None): 38 | '''Read version from first lines of file''' 39 | with open(filename) as f: 40 | for num, line in enumerate(f): 41 | if lines and num == lines: 42 | break 43 | match = VERSION.search(line) 44 | if match: 45 | return match.group(1) 46 | else: 47 | raise ValueError('version pattern not found in {}'.format(filename)) 48 | 49 | 50 | def read_git_ref(name): 51 | '''Dereference git commit ID''' 52 | command = 'git show-ref -s --heads --tags'.split() + [name] 53 | return run(command, stdout=PIPE) 54 | 55 | 56 | def test_readme_changelog(): 57 | '''Compare version numbers in main script and CHANGELOG''' 58 | skip_development_versions() 59 | app_version = read_version(BCPP, lines=5) 60 | changelog_version = read_version(CHANGELOG, lines=5) 61 | assert app_version == changelog_version 62 | 63 | 64 | @skipif_no_git 65 | def test_git_tag(): 66 | '''Compare version numbers in main script and git tag''' 67 | skip_development_versions() 68 | app_version = read_version(BCPP, lines=5) 69 | command = 'git log -1 --format=%D --'.split() + [BCPP] 70 | output = run(command, stdout=PIPE) 71 | match = VERSION.search(output) 72 | if not match: 73 | raise AssertionError('version pattern not found in {}'.format(' '.join(command))) 74 | git_version = match.group(1) 75 | assert app_version == git_version 76 | 77 | 78 | @skipif_no_git 79 | def test_git_stable(): 80 | '''Check that git stable tag points to the latest CHANGELOG entry''' 81 | skip_development_versions() 82 | stable = read_git_ref('stable') 83 | changelog = read_git_ref(read_version(CHANGELOG, lines=5)) 84 | assert stable == changelog 85 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Automated tests for bash-complete-partial-path 2 | 3 | ## Running tests 4 | 5 | Execute `make test` from repo's top directory 6 | 7 | 8 | ## Dependencies 9 | 10 | Test environment needs to provide: 11 | 12 | - Python 3.4+ 13 | - GNU Make 14 | - Curl 15 | - sha256sum (from GNU Coreutils) 16 | 17 | _* curl and sha256sum may be avoided if you fetch Makefile.venv manually_ 18 | 19 | And all of bash-complete-partial-path dependencies: 20 | 21 | - GNU Bash 22 | - GNU Sed 23 | 24 | 25 | ## Tests implementation 26 | 27 | Automated tests are implemented in Python and make use of [pytest] and [pexpect]. 28 | Makefile provided with the test suite takes care of managing virtual 29 | environment for Python automatically, no system-wide changes to Python 30 | installation are made. 31 | 32 | Because of unconventional command line implementation automated tests can not 33 | be executed natively on Windows. Thanks to recent developments ([ConPty]) that may 34 | become possible in the future - if/when Windows will be fully supported by 35 | pexpect. 36 | 37 | [pytest]: https://docs.pytest.org/en/stable/ 38 | [pexpect]: https://pexpect.readthedocs.io/en/stable/ 39 | [ConPTY]: https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/ 40 | 41 | 42 | ## CI setup 43 | 44 | Automated tests are continuously executed after each push to this repo. 45 | 46 | - **Linux** tests are executed within [Docker containers] on the 47 | infrastructure provided by [GitHub Actions]. The following configurations are 48 | being tested: 49 | - Centos 7: bash 4.2, sed 4.2 50 | - Debian 9: bash 4.4, sed 4.4 51 | - Debian 10: bash 5.0, sed 4.7 52 | - Debian 11: bash 5.1, sed 4.7 53 | - Debian 12: bash 5.2, sed 4.9 *(Debian Bookworm is the testing branch of 54 | Debian, package versions are not frozen and may be updated)* 55 | - **macOS** tests are executed in [virtual environment] provided by [Cirrus CI]: 56 | - macOS Ventura: bash 5.2, sed 4.9 *(these numbers will change - packages 57 | are automatically updated to the latest version in each CI run)* 58 | - **FreeBSD** tests are executed in Google Cloud Platfom [VM images] on 59 | infrastructure provided by [Cirrus CI]: 60 | - FreeBSD 14.0: bash 5.2, sed 4.9 *(automatically updated in each CI run)* 61 | - **Windows** is not a native platform for bash, and there are several 62 | compatibility layers people use to work around that (msys2, cygwin, WSL). 63 | Currently continuous integration tests are executed only on **msys2** 64 | provided by [GitHub Actions]. 65 | 66 | [GitHub Actions]: https://github.com/features/actions 67 | [Docker containers]: docker/README.md 68 | [virtual environment]: https://cirrus-ci.org/guide/macOS/ 69 | [VM images]: https://cirrus-ci.org/guide/FreeBSD/ 70 | [Cirrus CI]: https://cirrus-ci.org/ 71 | 72 | 73 | ## Cirrus CI integration for forks of this repository 74 | 75 | When you fork this repository Linux tests will be automatically picked up by 76 | GitHub Actions, but FreeBSD/macOS tests are executed on another platform which 77 | will require a one-time setup. 78 | 79 | [This document](https://github.com/libvirt/libvirt/blob/master/ci/README.rst) describes 80 | the steps required to configure Cirrus CI integration. Authors of the document use 81 | GitLab, but the only difference will be that instead of "CI/CD Variables" you 82 | will need to configure Repository Secrets (menu path: Settings / Secrets / Actions) 83 | 84 | 85 | ## Test configuration 86 | 87 | ### Modifying test runner behavior 88 | 89 | The following environment variables affect behavior of test runner: 90 | 91 | - **BCPP_TEST_DEBUG** - 92 | If this variable is set, PDB session will be activated by one of the test 93 | cases. Standard `bash` fixture will be available in that session. 94 | - **BCPP_TEST_LOG_FILE** - 95 | Path to the file where test debug messages will be saved. 96 | - **BCPP_TEST_LOG_STDOUT** - 97 | Print test debug messages to stdout. Pytest shows stdout only for failed 98 | tests by default, see [documentation](https://docs.pytest.org/en/latest/capture.html). 99 | - **BCPP_TEST_PEXPECT_TIMEOUT** - 100 | Timeout in seconds for Pexpect to wait for terminal output. Increase this 101 | value if test runner is a slow or overloaded machine. 102 | - **BCPP_TEST_SCOP_COMPLETION** - 103 | Path to scop/bash-completion script for compatibility testing. If this 104 | variable is not set the corresponding tests will be skipped. 105 | 106 | Check if the list above is up to date: 107 | 108 | ``` 109 | $ git grep -woPh 'BCPP\w+' tests/|sort -u 110 | ``` 111 | 112 | ### Passing extra arguments to pytest 113 | 114 | Use **PYTEST_ADDOPTS** 115 | ([documentation](http://doc.pytest.org/en/latest/customize.html#adding-default-options)): 116 | 117 | - Stopping after the first failure: `make test PYTEST_ADDOPTS=-x` 118 | - Running specific test: `make test PYTEST_ADDOPTS='-k test_case_or_suite_name'` 119 | - Dropping into PDB on failures: `make test PYTEST_ADDOPTS=--pdb` 120 | - While in PDB you may interact with bash session via 121 | `bash.process.interact()`. Press `Ctrl+]` to detach from bash session 122 | and return to PDB. 123 | - Other examples: 124 | 125 | ``` 126 | $ make test PYTEST_ADDOPTS=-x 127 | $ make test PYTEST_ADDOPTS=-xv 128 | $ make test PYTEST_ADDOPTS='-xv -k TestShortcuts' 129 | $ make test PYTEST_ADDOPTS='-xvv -k test_case' 130 | $ make test PYTEST_ADDOPTS='-xvv -k test_env_clean' 131 | $ make test PYTEST_ADDOPTS='-xvv -k test_env_clean --pdb' 132 | ``` 133 | -------------------------------------------------------------------------------- /tests/common.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Reusable base objects for automating bash interaction 3 | ''' 4 | 5 | import os 6 | import platform 7 | import re 8 | import shlex 9 | import sys 10 | from itertools import chain 11 | from pathlib import Path 12 | 13 | import pexpect 14 | 15 | 16 | 17 | if platform.system() == 'Windows': # ptys are not available in Windows 18 | raise RuntimeError('Automated tests can not be executed on Windows ' 19 | 'because underlying tooling is not available yet: ' 20 | 'https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows' 21 | ) 22 | 23 | 24 | class BashSessionError(Exception): 25 | '''Raised by BashSession when bash encounters unhandled error''' 26 | 27 | 28 | class BashSession: 29 | '''Wrapper for interactive bash session''' 30 | 31 | ENCODING = 'utf-8' 32 | STARTUP = [ 33 | "bind 'set enable-bracketed-paste off'", 34 | "bind 'set bell-style none'", 35 | ] 36 | ENV_UNSET = [ 37 | # The following variables will be unset in test environment 38 | ] 39 | ENV_FORCE = { 40 | # The following variables will be force overwritten with these values 41 | 'PS1': '__>>>__', 42 | 'TERM': 'dumb', 43 | 'HISTFILE': '/dev/null', # Do not write history for test sessions 44 | } 45 | MARKER = '>>-!-<<' 46 | TIMEOUT = os.getenv('BCPP_TEST_PEXPECT_TIMEOUT', 60) 47 | 48 | def __init__(self, *a, 49 | cmd='bash', 50 | args='--norc --noprofile', 51 | env=None, 52 | startup=None, 53 | **ka): 54 | if a: 55 | raise ValueError('only keyword arguments are supported') 56 | self.PS1 = self.ENV_FORCE['PS1'] 57 | 58 | environment = os.environ.copy() 59 | for variable in self.ENV_UNSET: 60 | environment.pop(variable, None) 61 | if env: 62 | environment.update(env) 63 | environment.update(self.ENV_FORCE) 64 | 65 | self.process = pexpect.spawn( 66 | '{} {}'.format(cmd, args), 67 | env=environment, 68 | encoding=self.ENCODING, 69 | dimensions=(24, 160), # https://github.com/scop/bash-completion/blob/fb46fed657d6b6575974b2fd5a9b6529ed2472b7/test/t/conftest.py#L112-L115 70 | **ka 71 | ) 72 | for command in chain(self.STARTUP, startup or ()): 73 | self.execute(command) 74 | 75 | def complete(self, text, tabs=1, custom_tabs='', drop_colors=True): 76 | ''' 77 | Trigger completion after inputting text into interactive bash session 78 | 79 | Return completion results 80 | ''' 81 | self._clear_current_line() 82 | 83 | proc = self.process 84 | proc.send('{}{}'.format(text, custom_tabs or '\t' * tabs)) 85 | proc.expect_exact(text, timeout=self.TIMEOUT) 86 | proc.send(self.MARKER) 87 | match = proc.expect(re.escape(self.MARKER), timeout=self.TIMEOUT) 88 | output = proc.before.strip() 89 | proc.sendcontrol('c') # drop current input 90 | proc.expect_exact(self.PS1, timeout=self.TIMEOUT) 91 | return CompletionResult(command=text, output=output, prompt=self.PS1, drop_colors=drop_colors) 92 | 93 | def execute(self, command, timeout=-1, exitcode=0): 94 | ''' 95 | Execute a single command in interactive shell. Check its return code. 96 | 97 | Return terminal output after execution. 98 | ''' 99 | if timeout == -1: 100 | timeout = self.TIMEOUT 101 | 102 | self._clear_current_line() 103 | 104 | proc = self.process 105 | proc.sendline(command) 106 | proc.expect_exact(command, timeout=timeout) 107 | proc.expect_exact(self.PS1, timeout=timeout) 108 | output = proc.before.strip() 109 | 110 | echo = 'echo "$?"' 111 | proc.sendline(echo) 112 | proc.expect_exact(echo, timeout=timeout) 113 | proc.expect_exact(self.PS1, timeout=timeout) 114 | returned = proc.before.strip() 115 | if not returned: 116 | returned = '0' # macOS allows empty exit codes apparently: 117 | # https://github.com/sio/bash-complete-partial-path/runs/354401396 118 | if str(exitcode) != returned: 119 | message = '{command} exited with code {returned} (expected {exitcode})\n{output}' 120 | raise BashSessionError(message.format(**locals())) 121 | 122 | return output 123 | 124 | def _clear_current_line(self): 125 | '''Clear any input on the current line ''' 126 | self.process.sendcontrol('e') 127 | self.process.sendcontrol('u') 128 | 129 | 130 | class CompletionResult: 131 | COLOR_CODE = re.compile('\x1b' r'\[(?:(?:\d{0,3};?){1,4}m|K)') 132 | BACKSPACE = '\x08' 133 | 134 | def __init__(self, command, output, prompt, drop_colors=True): 135 | '''Parse completion results from raw completion output''' 136 | output = output.strip() 137 | 138 | # Clean up backspace characters 139 | cleaned = [] 140 | for position, char in enumerate(output): 141 | if char == self.BACKSPACE: 142 | if position == 0: 143 | cleaned = list(command) 144 | cleaned.pop() 145 | else: 146 | cleaned.append(char) 147 | output = ''.join(cleaned) 148 | 149 | # Clean up \r\rPS1 150 | output = re.sub(r'^\r+%s' % prompt, '', output) 151 | 152 | # Clean up color codes 153 | if drop_colors: 154 | output = self._clean_color_codes(output) 155 | 156 | # Parse output 157 | if prompt in output: 158 | variants, selected = (x.strip() for x in output.split(prompt)) 159 | else: 160 | variants = selected = output.strip() 161 | self._variants = variants 162 | self.selected = selected 163 | 164 | @property 165 | def variants(self): 166 | '''Split variant according to shell lexical rules''' 167 | return shlex.split(self._variants) if self._variants else [self.selected] 168 | 169 | def __contains__(self, item): 170 | return item in self.variants 171 | 172 | def __eq__(self, other): 173 | if isinstance(other, str) and sys.platform in {'win32', 'cygwin'}: 174 | for self_word, other_word in zip(*(shlex.split(x) for x in (str(self), other))): 175 | if self_word == other_word: 176 | continue 177 | self_path, other_path = Path(self_word), Path(other_word) 178 | if other_path.exists(): 179 | return other_path.samefile(self_path) 180 | return False 181 | return True 182 | elif isinstance(other, str): 183 | return str(self) == other 184 | elif isinstance(other, type(self)): 185 | return (self._variants == other._variants and 186 | self.selected == other.selected) 187 | else: 188 | return NotImplemented 189 | 190 | def __bool__(self): 191 | return bool(self.selected) or bool(self._variants) 192 | 193 | def __iter__(self): 194 | yield from self.variants 195 | 196 | def __repr__(self): 197 | return '<{cls} selected={selected!r}, variants={variants!r}>'.format( 198 | cls=self.__class__.__name__, 199 | selected=self.selected, 200 | variants=self.variants, 201 | ) 202 | 203 | def __str__(self): 204 | return self._variants or self.selected 205 | 206 | def __len__(self): 207 | return len(self.variants) 208 | 209 | def _clean_color_codes(self, text): 210 | '''Remove escape sequences for color codes from text''' 211 | return self.COLOR_CODE.sub('', text) 212 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Enhanced file path completion in bash 2 | 3 | This project adds incomplete file path expansion to bash (the feature that was 4 | originally unique to zsh). 5 | 6 | When the Tab key is pressed bash expands only the last piece of the path by 7 | default, but with the completion functions from this project it will assume any 8 | of path elements might be incomplete. For example: `cd /u/s/app` will 9 | produce nothing by default, but will be expanded to `cd /usr/share/applications` 10 | if you've configured bash to load this file. 11 | 12 | Introductory overview is available at 13 | [author's blog](https://potyarkin.com/posts/2018/enhanced-file-path-completion-in-bash-like-in-zsh/). 14 | 15 | Watch a demo screencast to see this feature in action: 16 | 17 | [![asciicast](https://asciinema.org/a/191776.svg)](https://asciinema.org/a/191776) 18 | 19 | To enable the described behavior source [**this file**][main] from your 20 | ~/.bashrc and run `_bcpp --defaults`. Supported features are: 21 | 22 | - Special characters in completed path are automatically escaped if present 23 | - Tilde expressions are properly expanded (as per [bash documentation]) 24 | - If user had started writing the path in quotes, no character escaping is 25 | applied. Instead the quote is closed with a matching character after expanding 26 | the path. 27 | - If [bash-completion] package is already in use, this code will safely override 28 | its `_filedir` function. No extra configuration is required, just make sure 29 | you source this project *after* the main bash-completion. 30 | 31 | Completion functions have been tested and reported to work on: 32 | 33 | - Linux (Debian 9, 10, 11) 34 | - macOS (requires gnu-sed from brew) 35 | - Windows (msys2, Git for Windows) 36 | 37 | [Automated tests](tests/README.md) are continuously executed 38 | on Linux, FreeBSD, macOS and Windows (msys2). 39 | 40 | 41 | ## Installation and updating 42 | 43 | First you need to copy [bash_completion][main] file to your machine. Copy and 44 | paste the following commands into your terminal to fetch the latest version of 45 | the script to the default location (requires `curl` to be installed). 46 | 47 | ```shell 48 | # Install or update bash-complete-partial-path 49 | mkdir -p "$HOME/.config/bash-complete-partial-path/" && \ 50 | curl \ 51 | -o "$HOME/.config/bash-complete-partial-path/bash_completion" \ 52 | "https://raw.githubusercontent.com/sio/bash-complete-partial-path/stable/bash_completion" 53 | ``` 54 | 55 | To enable the new completion behavior put the following lines into your 56 | `~/.bashrc` (or your OS equivalent). 57 | 58 | ```shell 59 | # Enhanced file path completion in bash - https://github.com/sio/bash-complete-partial-path 60 | if [ -s "$HOME/.config/bash-complete-partial-path/bash_completion" ] 61 | then 62 | source "$HOME/.config/bash-complete-partial-path/bash_completion" 63 | _bcpp --defaults 64 | fi 65 | ``` 66 | 67 | Make sure you source this project *after* the main bash-completion which may be 68 | included in your `~/.bashrc` file. 69 | 70 | 71 | ## Runtime requirements 72 | 73 | To use this completion script make sure your OS provides the following 74 | dependencies: 75 | 76 | - GNU Bash, version 4 or newer (version 3.2 is not yet supported, see 77 | [#8](https://github.com/sio/bash-complete-partial-path/issues/8)) 78 | - GNU Sed (install it with brew on macOS) 79 | - Core unix-like userland (mktemp, mkfifo, rm) 80 | 81 | 82 | ## Custom feature selection 83 | 84 | If you like the project idea overall but do not agree with default behavior, 85 | you can select which features to enable with `_bcpp` manager function. Sourcing 86 | the file without calling this function has no side effects. 87 | 88 | ``` 89 | Usage: _bcpp OPTIONS 90 | Manage enhanced path completion in bash 91 | 92 | Options: 93 | --defaults 94 | Enable the subset of features recommended by maintainer. 95 | Currently equals to: 96 | "--files --dirs --cooperate --nocase --readline" 97 | --all 98 | Enable all optional features. Equals to: 99 | "--files --dirs --cooperate --nocase --readline" 100 | --help 101 | Show this help message 102 | 103 | Individual feature flags: 104 | --files 105 | Enable enhanced completion for file paths 106 | --dirs 107 | Complete `cd` with paths to directories only 108 | --cooperate 109 | Cooperate with system-wide bash-completion if it's in use. 110 | This function must be invoked AFTER the main bash-completion 111 | is loaded. 112 | Deprecated alias: --override 113 | --nocase 114 | Make path completion case insensitive 115 | --readline 116 | Configure readline for better user experience. Equals to: 117 | "--readline-menu --readline-color --readline-misc" 118 | --readline-color 119 | Enable colors in completion 120 | --readline-menu 121 | Use `menu-complete` when Tab key is pressed instead of default 122 | `complete`. Use Shift+Tab to return to previous suggestion 123 | --readline-misc 124 | Other useful readline tweaks 125 | ``` 126 | 127 | 128 | ## Working together with other completion scripts 129 | 130 | Partial path completion provided by this project is designed to work correctly 131 | when [bash-completion] is in use (see `--cooperate` flag). Make sure you 132 | invoke `_bcpp` after the main completion script has been sourced. 133 | 134 | Enhanced completion will work for most, but not all commands unfortunately. 135 | Some completion scripts within [bash-completion] project do not rely on global 136 | `_filedir*` functions but instead implement their own logic for path 137 | completion. For such scripts there is no simple way to inject modified 138 | completion algorithm without disabling the rest of their functionality. 139 | 140 | If for any particular command you'll prefer partial path completion over its 141 | provided completion script, you can run `complete -F _bcpp_complete_file 142 | COMMANDNAME` (and/or add that to ~/.bashrc) 143 | 144 | 145 | ## Support 146 | 147 | #### Issue tracker 148 | 149 | GitHub's [issue tracker] is the primary venue for asking and answering support 150 | questions. Please don't forget to search closed issues for the topic you're 151 | interested in! 152 | 153 | If you know an answer to the question asked by someone else, please do not 154 | hesitate to post it! That would be a great help to the project! 155 | 156 | #### Email 157 | 158 | If for some reason you'd rather not use the [issue tracker], contacting me via 159 | email is OK too. Please use a descriptive subject line to enhance visibility 160 | of your message. Also please keep in mind that support through the channels 161 | accessible to the public is preferable because one answer can help many people 162 | who might read it later. 163 | 164 | My email is visible under the GitHub profile and in the commit log. 165 | 166 | #### Community support 167 | 168 | You might get faster and more interactive support from other users. 169 | 170 | This project does not (yet) have a dedicated community venue, but experienced 171 | Linux users will most likely be able to figure out most common questions. You 172 | can try asking at the local Linux-related forums, IRC/Discord/Telegram chats 173 | or on Reddit/StackOverflow. 174 | 175 | 176 | ## Contributing 177 | 178 | Thank you for taking an interest in this project! If you wish to improve it 179 | please open an issue or create a pull request. 180 | If you just want to share your emotions, we encourage you to do so 181 | [here](https://github.com/sio/bash-complete-partial-path/issues/6)! 182 | 183 | Your help is most needed in the following areas: 184 | 185 | - Documenting the project 186 | - Finding (and fixing) existing bugs 187 | - Testing the script on other operating systems and reporting the results (both 188 | positive and negative) 189 | - Expanding OS support (if it's lacking) 190 | - Adding better demo asciicasts and screenshots 191 | 192 | The project was created to do one thing (autocomplete partial paths) and to do 193 | it well. Please try to keep all code in one file and to keep it short. Major new 194 | functionality is probably better suited for a separate project. 195 | 196 | I'm open to dialog and I promise to behave responsibly and treat all 197 | contributors with respect. Please try to do the same, and treat others the way 198 | you want to be treated. 199 | 200 | Thank you again! 201 | 202 | 203 | ## Information for developers 204 | 205 | #### Debugging 206 | 207 | Executing `set -v; set -x` before attempting completion enables printing a lot 208 | of useful debugging information 209 | 210 | #### Automated testing 211 | 212 | Tests are implemented with Python and Pexpect. [Read more here](tests/README.md) 213 | 214 | 215 | ## License and copyright 216 | 217 | Copyright © 2018-2019 Vitaly Potyarkin 218 | 219 | ``` 220 | Licensed under the Apache License, Version 2.0 (the "License"); 221 | you may not use these files except in compliance with the License. 222 | You may obtain a copy of the License at 223 | 224 | http://www.apache.org/licenses/LICENSE-2.0 225 | 226 | Unless required by applicable law or agreed to in writing, software 227 | distributed under the License is distributed on an "AS IS" BASIS, 228 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 229 | See the License for the specific language governing permissions and 230 | limitations under the License. 231 | ``` 232 | 233 | [bash-completion]: https://github.com/scop/bash-completion 234 | [bash documentation]: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html 235 | [main]: bash_completion 236 | [issue tracker]: https://github.com/sio/bash-complete-partial-path/issues 237 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /bash_completion: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # bash-complete-partial-path v1.1.0-dev 4 | # 5 | # Zsh-like expansion of incomplete file paths for Bash. 6 | # Source this file from your ~/.bashrc and use `_bcpp --defaults` 7 | # to enable the described behavior. 8 | # 9 | # Example: `/u/s/a` will be expanded into `/usr/share/applications` 10 | # 11 | # https://github.com/sio/bash-complete-partial-path 12 | # 13 | 14 | 15 | # Copyright 2018-2019 Vitaly Potyarkin 16 | # 17 | # Licensed under the Apache License, Version 2.0 (the "License"); 18 | # you may not use this file except in compliance with the License. 19 | # You may obtain a copy of the License at 20 | # 21 | # http://www.apache.org/licenses/LICENSE-2.0 22 | # 23 | # Unless required by applicable law or agreed to in writing, software 24 | # distributed under the License is distributed on an "AS IS" BASIS, 25 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | # See the License for the specific language governing permissions and 27 | # limitations under the License. 28 | 29 | 30 | # 31 | # Detect sed binary once at load time 32 | # 33 | _bcpp_sed_detect() { 34 | local SED GNU_SED 35 | SED="sed" 36 | GNU_SED="gsed" # macOS ships BSD sed by default, gnu-sed has to be installed with brew 37 | if [[ $OSTYPE == darwin* || $OSTYPE == freebsd* ]] 38 | then 39 | if type "$GNU_SED" &> /dev/null 40 | then 41 | SED="$GNU_SED" 42 | else 43 | echo "bash-complete-partial-path: Please install GNU sed (gsed)" >&2 44 | fi 45 | fi 46 | echo "command $SED" 47 | } 48 | 49 | 50 | # 51 | # Take a single incomplete path and fill it with wildcards 52 | # e.g. /u/s/app/ -> /u*/s*/app* 53 | # 54 | _bcpp_put_wildcards() { 55 | local PROCESSED TILDE_EXPANSION INPUT 56 | 57 | INPUT="$*" 58 | PROCESSED=$( \ 59 | echo "$INPUT" | \ 60 | $_BCPP_SED \ 61 | -Ee 's:([^\*\~])/:\1*/:g; 62 | s:([^\/\*])$:\1*:g; 63 | s:^(\~[^\/]*)\*\/:\1/:; 64 | s:(\.+)\*/:\1/:g; 65 | s:(^|/)(\$[^/]+)\*(/|$):\2\3:g' 66 | ) 67 | eval "TILDE_EXPANSION=$(\ 68 | printf \ 69 | '%q' \ 70 | "$PROCESSED"|$_BCPP_SED -e 's:^\\\~:~:g' -Ee 's:(^|/)\\(\$):\1\2:g' \ 71 | )" 72 | 73 | # Workaround for Mingw pseudo directories for drives, 74 | # i.e. `/c/` refers to drive `C:\`, but glob `/c*/` returns no matches 75 | if [[ "$INPUT" =~ ^\/[a-zA-Z]\/.* && -d "${INPUT::2}" ]] 76 | then 77 | TILDE_EXPANSION="${TILDE_EXPANSION::2}${TILDE_EXPANSION:3}" 78 | fi 79 | 80 | echo "$TILDE_EXPANSION" 81 | } 82 | 83 | 84 | # Run a job in background without printing job control messages and without a 85 | # subshell 86 | # https://stackoverflow.com/a/51061046 87 | _bcpp_silent_bg() { 88 | { 2>&3 "$@"& } 3>&2 2>/dev/null 89 | builtin disown &>/dev/null # Prevent whine if job has already completed 90 | return 0 # do not clutter $? value (last exit code) 91 | } 92 | 93 | # Helper function for wrapping compgen output to named pipe 94 | _bcpp_compgen() { 95 | local wildcards="$1" 96 | local pipe="$2" 97 | compgen -G "$wildcards" "$wildcards" 2>/dev/null >"$pipe" 98 | } 99 | 100 | # 101 | # Bash completion function for expanding partial paths 102 | # 103 | # This is a generic worker. It accepts 'file' or 'directory' as the first 104 | # argument to specify desired completion behavior 105 | # 106 | _bcpp_complete() { 107 | local WILDCARDS ACTION LINE OPTION INPUT QUOTE 108 | 109 | ACTION="$1" 110 | if [[ "_$1" == "_-d" ]] 111 | then # _filedir compatibility 112 | ACTION="directory" 113 | fi 114 | if [[ "$COMP_CWORD" -ge 0 ]] 115 | then 116 | INPUT="${COMP_WORDS[$COMP_CWORD]}" 117 | else 118 | INPUT="" 119 | fi 120 | 121 | # Detect and strip opened quotes 122 | if [[ "${INPUT:0:1}" == "'" || "${INPUT:0:1}" == '"' ]] 123 | then 124 | QUOTE="${INPUT:0:1}" 125 | INPUT="${INPUT:1}" 126 | else 127 | QUOTE="" 128 | fi 129 | 130 | # Prepare the reply 131 | COMPREPLY=() 132 | compopt -o nospace 133 | compopt -o bashdefault 134 | compopt -o default 135 | 136 | # If input is already a valid path, do not try to be clever 137 | if [[ -e "$INPUT" ]] 138 | then 139 | if [[ "_$ACTION" == "_directory" ]] 140 | then 141 | OPTION="dirnames" 142 | else 143 | OPTION="filenames" 144 | fi 145 | if [[ -d "$INPUT" && "${INPUT: -1}" != '/' ]] 146 | then 147 | COMPREPLY=("$INPUT/") 148 | else 149 | readarray -t COMPREPLY < <(compgen -o "$OPTION" "$INPUT") 150 | local i 151 | for i in "${!COMPREPLY[@]}" 152 | do 153 | COMPREPLY[i]="$(printf "%q" "${COMPREPLY[i]}")" 154 | done 155 | fi 156 | return 157 | fi 158 | 159 | # Add wildcards to each path element 160 | WILDCARDS=$(_bcpp_put_wildcards "$INPUT") 161 | 162 | # Collect completion options 163 | local pipe 164 | pipe="$_BCPP_FIFO" 165 | [[ -z "$pipe" ]] && return 1 # fail on empty filename 166 | command mkfifo "$pipe" 167 | 168 | local monitor 169 | [[ "$-" == *m* ]] && monitor=yes || monitor=no 170 | [[ "$monitor" == yes ]] && set +m 171 | 172 | _bcpp_silent_bg _bcpp_compgen "$WILDCARDS" "$pipe" 173 | while read -r -d $'\n' LINE 174 | do 175 | if [[ "_$ACTION" == "_directory" && ! -d "$LINE" ]] 176 | then # skip non-directory paths when looking for directory 177 | continue 178 | fi 179 | if [[ -z "$LINE" ]] 180 | then # skip empty suggestions 181 | continue 182 | fi 183 | if [[ -z "$QUOTE" ]] 184 | then # escape special characters unless user has opened a quote 185 | LINE=$(printf "%q" "$LINE") 186 | fi 187 | COMPREPLY+=("$LINE") 188 | done < "$pipe" 189 | command rm "$pipe" 190 | [[ "$monitor" == yes ]] && set -m 191 | } 192 | 193 | 194 | # Wrappers 195 | _bcpp_complete_dir() { _bcpp_complete directory; } 196 | _bcpp_complete_file() { _bcpp_complete file; } 197 | 198 | 199 | # Manage enhanced path completion 200 | _bcpp() { 201 | local DEFAULT ALL KEYS ARG USAGE UNKNOWN 202 | 203 | DEFAULT="--files --dirs --cooperate --nocase --readline" 204 | ALL="--files --dirs --cooperate --nocase --readline" 205 | USAGE=( 206 | "Usage: ${FUNCNAME[0]} OPTIONS" 207 | " Manage enhanced path completion in bash" 208 | "" 209 | "Options:" 210 | " --defaults" 211 | " Enable the subset of features recommended by maintainer." 212 | " Currently equals to:" 213 | " \"$DEFAULT\"" 214 | " --all" 215 | " Enable all optional features. Equals to:" 216 | " \"$ALL\"" 217 | " --help" 218 | " Show this help message" 219 | "" 220 | "Individual feature flags:" 221 | " --files" 222 | " Enable enhanced completion for file paths" 223 | " --dirs" 224 | " Complete \`cd\` with paths to directories only" 225 | " --cooperate" 226 | " Cooperate with system-wide bash-completion if it's in use." 227 | " This function must be invoked AFTER the main bash-completion" 228 | " is loaded." 229 | " Deprecated alias: --override" 230 | " --nocase" 231 | " Make path completion case insensitive" 232 | " --readline" 233 | " Configure readline for better user experience. Equals to:" 234 | " \"--readline-menu --readline-color --readline-misc\"" 235 | " --readline-color" 236 | " Enable colors in completion" 237 | " --readline-menu" 238 | " Use \`menu-complete\` when Tab key is pressed instead of default" 239 | " \`complete\`. Use Shift+Tab to return to previous suggestion" 240 | " --readline-misc" 241 | " Other useful readline tweaks" 242 | "" 243 | "Copyright 2018-2019 Vitaly Potyarkin" 244 | "" 245 | "" 246 | "This program is Free Software and comes with ABSOLUTELY NO WARRANTY," 247 | "to the extent permitted by applicable law. For more information see:" 248 | "" 249 | ) 250 | 251 | # Modify selected features list 252 | for ARG in "$@" 253 | do 254 | case "$ARG" in 255 | --defaults) 256 | # shellcheck disable=SC2086 257 | set -- "$@" $DEFAULT ;; 258 | --all) 259 | # shellcheck disable=SC2086 260 | set -- "$@" $ALL ;; 261 | esac 262 | done 263 | 264 | # Detect selected features 265 | KEYS="" 266 | for ARG in "$@" 267 | do 268 | case "$ARG" in 269 | --files) 270 | KEYS="${KEYS}f" ;; 271 | --dirs) 272 | KEYS="${KEYS}d" ;; 273 | --cooperate|--override) 274 | KEYS="${KEYS}o" ;; 275 | --nocase) 276 | KEYS="${KEYS}c" ;; 277 | --readline) 278 | KEYS="${KEYS}mlr" ;; 279 | --readline-menu) 280 | KEYS="${KEYS}m" ;; 281 | --readline-color) 282 | KEYS="${KEYS}l" ;; 283 | --readline-misc) 284 | KEYS="${KEYS}r" ;; 285 | --help|--usage|-h) 286 | KEYS="${KEYS}H" ;; 287 | --defaults|--all) 288 | ;; 289 | *) 290 | KEYS="${KEYS}U" 291 | UNKNOWN+=("$ARG") 292 | ;; 293 | esac 294 | done 295 | 296 | # Special cases that terminate function 297 | if [[ "$KEYS" == *H* || -z "$*" ]] # --help|--usage|-h 298 | then 299 | printf "%s\n" "${USAGE[@]}" 300 | return 0 301 | fi 302 | if [[ "$KEYS" == *U* ]] # unknown arguments 303 | then 304 | echo -e \ 305 | "Unknown arguments: ${UNKNOWN[*]}" \ 306 | "\nRefer to \`${FUNCNAME[0]} --help\` for more information" \ 307 | >&2 308 | return 1 309 | fi 310 | 311 | # Enable selected functionality. The order of execution does not depend on 312 | # the order of command line parameters 313 | if [[ "$KEYS" == *o* ]] # --cooperate|--override 314 | then 315 | local DYNAMIC 316 | DYNAMIC=$(complete -p|grep -E -- '-D.*_completion_loader|_completion_loader.*-D|_python_argcomplete_global.*-D') 317 | 318 | local _bcpp_filedir_original_code 319 | _bcpp_filedir_original_code=$(declare -f _filedir|tail -n+2) 320 | if [[ -n "$_bcpp_filedir_original_code" ]] 321 | then 322 | type _bcpp_filedir_original &>/dev/null || \ 323 | eval "_bcpp_filedir_original() $_bcpp_filedir_original_code" 324 | 325 | # shellcheck disable=SC2329 # invoked from outside of this script 326 | _filedir() { 327 | _bcpp_filedir_original "$@" 328 | [ "${#COMPREPLY[@]}" -eq 0 ] && _bcpp_complete "$@" 329 | } 330 | fi 331 | 332 | local _bcpp_filedir_xspec_original_code 333 | _bcpp_filedir_xspec_original_code=$(declare -f _filedir_xspec|tail -n+2) 334 | if [[ -n "$_bcpp_filedir_xspec_original_code" ]] 335 | then 336 | type _bcpp_filedir_xspec_original &>/dev/null || \ 337 | eval "_bcpp_filedir_xspec_original() $_bcpp_filedir_xspec_original_code" 338 | 339 | # shellcheck disable=SC2329 # invoked from outside of this script 340 | _filedir_xspec() { 341 | _bcpp_filedir_xspec_original "$@" 342 | [ "${#COMPREPLY[@]}" -eq 0 ] && _bcpp_complete "$@" 343 | } 344 | fi 345 | fi 346 | if [[ "$KEYS" == *f* ]] # --files 347 | then 348 | # Do not overwrite default completion function if dynamic completion 349 | # loader is enabled 350 | [[ -z "$DYNAMIC" ]] && complete -D -F _bcpp_complete_file 351 | fi 352 | if [[ "$KEYS" == *d* ]] # --dirs 353 | then 354 | complete -F _bcpp_complete_dir cd 355 | complete -F _bcpp_complete_dir pushd 356 | fi 357 | if [[ "$KEYS" == *c* ]] # --nocase 358 | then 359 | shopt -s nocaseglob 360 | bind 'set completion-ignore-case on' 361 | fi 362 | if [[ "$KEYS" == *m* ]] # --readline-menu 363 | then 364 | bind 'TAB:menu-complete' 365 | bind '"\e[Z": menu-complete-backward' # Shift+Tab 366 | bind 'set menu-complete-display-prefix on' 367 | fi 368 | if [[ "$KEYS" == *l* ]] # --readline-color 369 | then 370 | bind 'set colored-completion-prefix on' 371 | bind 'set colored-stats on' 372 | fi 373 | if [[ "$KEYS" == *r* ]] # --readline-misc 374 | then 375 | bind 'set show-all-if-ambiguous on' 376 | bind 'set show-all-if-unmodified on' 377 | fi 378 | 379 | # Calculate location for fifo file 380 | _BCPP_FIFO=$(mktemp -u --tmpdir 'bcpp_pipe_XXXXXXXX' 2>/dev/null || mktemp -u -t 'bcpp_pipe') 381 | 382 | # Detect sed command 383 | _BCPP_SED=$(_bcpp_sed_detect) 384 | } 385 | -------------------------------------------------------------------------------- /docs/demo.asciicast: -------------------------------------------------------------------------------- 1 | { 2 | "height": 20, 3 | "command": null, 4 | "title": null, 5 | "version": 1, 6 | "stdout": [ 7 | [ 8 | 0.120538, 9 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n" 10 | ], 11 | [ 12 | 0.000565, 13 | "\u001b[1;33m$ \u001b[0m" 14 | ], 15 | [ 16 | 0.5, 17 | "#" 18 | ], 19 | [ 20 | 0.276881, 21 | " " 22 | ], 23 | [ 24 | 0.165066, 25 | "T" 26 | ], 27 | [ 28 | 0.363575, 29 | "h" 30 | ], 31 | [ 32 | 0.101179, 33 | "i" 34 | ], 35 | [ 36 | 0.32294, 37 | "s" 38 | ], 39 | [ 40 | 0.428833, 41 | " " 42 | ], 43 | [ 44 | 0.106202, 45 | "i" 46 | ], 47 | [ 48 | 0.127708, 49 | "s" 50 | ], 51 | [ 52 | 0.074588, 53 | " " 54 | ], 55 | [ 56 | 0.20869, 57 | "a" 58 | ], 59 | [ 60 | 0.122527, 61 | " " 62 | ], 63 | [ 64 | 0.214913, 65 | "d" 66 | ], 67 | [ 68 | 0.181591, 69 | "e" 70 | ], 71 | [ 72 | 0.096342, 73 | "m" 74 | ], 75 | [ 76 | 0.090389, 77 | "o" 78 | ], 79 | [ 80 | 0.159253, 81 | " " 82 | ], 83 | [ 84 | 0.198195, 85 | "o" 86 | ], 87 | [ 88 | 0.111925, 89 | "f" 90 | ], 91 | [ 92 | 0.10705, 93 | " " 94 | ], 95 | [ 96 | 0.349792, 97 | "e" 98 | ], 99 | [ 100 | 0.219289, 101 | "n" 102 | ], 103 | [ 104 | 0.3507, 105 | "h" 106 | ], 107 | [ 108 | 0.146347, 109 | "a" 110 | ], 111 | [ 112 | 0.142254, 113 | "n" 114 | ], 115 | [ 116 | 0.292517, 117 | "c" 118 | ], 119 | [ 120 | 0.22841, 121 | "e" 122 | ], 123 | [ 124 | 0.219641, 125 | "d" 126 | ], 127 | [ 128 | 0.113404, 129 | " " 130 | ], 131 | [ 132 | 0.5, 133 | "f" 134 | ], 135 | [ 136 | 0.079762, 137 | "i" 138 | ], 139 | [ 140 | 0.095695, 141 | "l" 142 | ], 143 | [ 144 | 0.095701, 145 | "e" 146 | ], 147 | [ 148 | 0.220343, 149 | "p" 150 | ], 151 | [ 152 | 0.106601, 153 | "a" 154 | ], 155 | [ 156 | 0.258368, 157 | "t" 158 | ], 159 | [ 160 | 0.095853, 161 | "h" 162 | ], 163 | [ 164 | 0.149382, 165 | " " 166 | ], 167 | [ 168 | 0.5, 169 | "c" 170 | ], 171 | [ 172 | 0.079869, 173 | "o" 174 | ], 175 | [ 176 | 0.069328, 177 | "m" 178 | ], 179 | [ 180 | 0.207127, 181 | "p" 182 | ], 183 | [ 184 | 0.247423, 185 | "l" 186 | ], 187 | [ 188 | 0.12829, 189 | "e" 190 | ], 191 | [ 192 | 0.187354, 193 | "t" 194 | ], 195 | [ 196 | 0.101262, 197 | "i" 198 | ], 199 | [ 200 | 0.085346, 201 | "o" 202 | ], 203 | [ 204 | 0.101234, 205 | "n" 206 | ], 207 | [ 208 | 0.222822, 209 | " " 210 | ], 211 | [ 212 | 0.26384, 213 | "f" 214 | ], 215 | [ 216 | 0.085044, 217 | "o" 218 | ], 219 | [ 220 | 0.155794, 221 | "r" 222 | ], 223 | [ 224 | 0.047692, 225 | " " 226 | ], 227 | [ 228 | 0.292646, 229 | "b" 230 | ], 231 | [ 232 | 0.101235, 233 | "a" 234 | ], 235 | [ 236 | 0.185701, 237 | "s" 238 | ], 239 | [ 240 | 0.144041, 241 | "h" 242 | ], 243 | [ 244 | 0.5, 245 | "\r\n" 246 | ], 247 | [ 248 | 0.01054, 249 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 250 | ], 251 | [ 252 | 0.5, 253 | "#" 254 | ], 255 | [ 256 | 0.5, 257 | " " 258 | ], 259 | [ 260 | 0.5, 261 | "f" 262 | ], 263 | [ 264 | 0.142622, 265 | "i" 266 | ], 267 | [ 268 | 0.116766, 269 | "l" 270 | ], 271 | [ 272 | 0.184619, 273 | "e" 274 | ], 275 | [ 276 | 0.379495, 277 | "s" 278 | ], 279 | [ 280 | 0.272976, 281 | ":" 282 | ], 283 | [ 284 | 0.348018, 285 | "\r\n" 286 | ], 287 | [ 288 | 0.009719, 289 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 290 | ], 291 | [ 292 | 0.5, 293 | "l" 294 | ], 295 | [ 296 | 0.100941, 297 | "s" 298 | ], 299 | [ 300 | 0.122195, 301 | " " 302 | ], 303 | [ 304 | 0.5, 305 | "u" 306 | ], 307 | [ 308 | 0.5, 309 | "/" 310 | ], 311 | [ 312 | 0.128028, 313 | "s" 314 | ], 315 | [ 316 | 0.095541, 317 | "/" 318 | ], 319 | [ 320 | 0.322867, 321 | "a" 322 | ], 323 | [ 324 | 0.095796, 325 | "p" 326 | ], 327 | [ 328 | 0.150862, 329 | "p" 330 | ], 331 | [ 332 | 0.207344, 333 | "\r\n" 334 | ], 335 | [ 336 | 0.000576, 337 | "\u001b[01;35musr/share/app\u001b[0m\u001b[K-file\u001b[0m\u001b[K \u001b[01;35musr/share/app\u001b[0m\u001b[K\u001b[01;34mlications\u001b[0m\u001b[K \u001b[01;35musr/share/app\u001b[0m\u001b[K\u001b[01;34m-second-dir\u001b[0m\u001b[K\r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mls usr/share/app\u0007" 338 | ], 339 | [ 340 | 0.5, 341 | "-file" 342 | ], 343 | [ 344 | 0.5, 345 | "\b\b\b\b\blications" 346 | ], 347 | [ 348 | 0.5, 349 | "\r\n" 350 | ], 351 | [ 352 | 0.004607, 353 | "app-one app-two\r\n" 354 | ], 355 | [ 356 | 0.010995, 357 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 358 | ], 359 | [ 360 | 0.5, 361 | "#" 362 | ], 363 | [ 364 | 0.389559, 365 | " " 366 | ], 367 | [ 368 | 0.079935, 369 | "d" 370 | ], 371 | [ 372 | 0.117131, 373 | "i" 374 | ], 375 | [ 376 | 0.13408, 377 | "r" 378 | ], 379 | [ 380 | 0.138855, 381 | "e" 382 | ], 383 | [ 384 | 0.373375, 385 | "c" 386 | ], 387 | [ 388 | 0.248189, 389 | "t" 390 | ], 391 | [ 392 | 0.427366, 393 | "o" 394 | ], 395 | [ 396 | 0.232305, 397 | "r" 398 | ], 399 | [ 400 | 0.095607, 401 | "i" 402 | ], 403 | [ 404 | 0.124907, 405 | "e" 406 | ], 407 | [ 408 | 0.274596, 409 | "s" 410 | ], 411 | [ 412 | 0.289298, 413 | ":" 414 | ], 415 | [ 416 | 0.361062, 417 | "\r\n" 418 | ], 419 | [ 420 | 0.010784, 421 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n" 422 | ], 423 | [ 424 | 0.000515, 425 | "\u001b[1;33m$ \u001b[0m" 426 | ], 427 | [ 428 | 0.5, 429 | "c" 430 | ], 431 | [ 432 | 0.171881, 433 | "d" 434 | ], 435 | [ 436 | 0.106137, 437 | " " 438 | ], 439 | [ 440 | 0.5, 441 | "u" 442 | ], 443 | [ 444 | 0.290508, 445 | "/" 446 | ], 447 | [ 448 | 0.208256, 449 | "s" 450 | ], 451 | [ 452 | 0.074593, 453 | "/" 454 | ], 455 | [ 456 | 0.5, 457 | "a" 458 | ], 459 | [ 460 | 0.090489, 461 | "p" 462 | ], 463 | [ 464 | 0.5, 465 | "\r\n" 466 | ], 467 | [ 468 | 0.000482, 469 | "\u001b[01;35musr/share/app\u001b[0m\u001b[K\u001b[01;34mlications\u001b[0m\u001b[K \u001b[01;35musr/share/app\u001b[0m\u001b[K\u001b[01;34m-second-dir\u001b[0m\u001b[K \r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mcd usr/share/app\u0007" 470 | ], 471 | [ 472 | 0.5, 473 | "lications" 474 | ], 475 | [ 476 | 0.5, 477 | "\r\n" 478 | ], 479 | [ 480 | 0.002739, 481 | "app-one app-two\r\n" 482 | ], 483 | [ 484 | 0.009899, 485 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/usr/share/applications/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 486 | ], 487 | [ 488 | 0.5, 489 | "c" 490 | ], 491 | [ 492 | 0.053071, 493 | "d" 494 | ], 495 | [ 496 | 0.116941, 497 | " " 498 | ], 499 | [ 500 | 0.106949, 501 | "-" 502 | ], 503 | [ 504 | 0.274004, 505 | "\r\n" 506 | ], 507 | [ 508 | 0.000713, 509 | "/tmp/demo\r\n" 510 | ], 511 | [ 512 | 0.003434, 513 | "\u001b[0m\u001b[01;34musr\u001b[0m/\r\n" 514 | ], 515 | [ 516 | 0.009047, 517 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 518 | ], 519 | [ 520 | 0.5, 521 | "#" 522 | ], 523 | [ 524 | 0.5, 525 | " " 526 | ], 527 | [ 528 | 0.116832, 529 | "t" 530 | ], 531 | [ 532 | 0.095912, 533 | "i" 534 | ], 535 | [ 536 | 0.101606, 537 | "l" 538 | ], 539 | [ 540 | 0.315712, 541 | "d" 542 | ], 543 | [ 544 | 0.188005, 545 | "e" 546 | ], 547 | [ 548 | 0.139422, 549 | " " 550 | ], 551 | [ 552 | 0.352816, 553 | "e" 554 | ], 555 | [ 556 | 0.5, 557 | "x" 558 | ], 559 | [ 560 | 0.137787, 561 | "p" 562 | ], 563 | [ 564 | 0.199609, 565 | "a" 566 | ], 567 | [ 568 | 0.141462, 569 | "n" 570 | ], 571 | [ 572 | 0.5, 573 | "s" 574 | ], 575 | [ 576 | 0.09048, 577 | "i" 578 | ], 579 | [ 580 | 0.074422, 581 | "o" 582 | ], 583 | [ 584 | 0.122781, 585 | "n" 586 | ], 587 | [ 588 | 0.5, 589 | "\r\n" 590 | ], 591 | [ 592 | 0.00672, 593 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 594 | ], 595 | [ 596 | 0.491044, 597 | "l" 598 | ], 599 | [ 600 | 0.069392, 601 | "s" 602 | ], 603 | [ 604 | 0.101076, 605 | " " 606 | ], 607 | [ 608 | 0.359053, 609 | "~" 610 | ], 611 | [ 612 | 0.371734, 613 | "/" 614 | ], 615 | [ 616 | 0.271457, 617 | "p" 618 | ], 619 | [ 620 | 0.267286, 621 | "/" 622 | ], 623 | [ 624 | 0.5, 625 | "n" 626 | ], 627 | [ 628 | 0.06915, 629 | "o" 630 | ], 631 | [ 632 | 0.251832, 633 | "\b\b\b\b\b\b/home/user/projects/notes" 634 | ], 635 | [ 636 | 0.5, 637 | "^C\r\n" 638 | ], 639 | [ 640 | 0.010036, 641 | "\u001b[31mExit code: 130\r\n\r\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 642 | ], 643 | [ 644 | 0.5, 645 | "#" 646 | ], 647 | [ 648 | 0.5, 649 | " " 650 | ], 651 | [ 652 | 0.106548, 653 | "a" 654 | ], 655 | [ 656 | 0.175958, 657 | "d" 658 | ], 659 | [ 660 | 0.5, 661 | "v" 662 | ], 663 | [ 664 | 0.069159, 665 | "a" 666 | ], 667 | [ 668 | 0.190579, 669 | "n" 670 | ], 671 | [ 672 | 0.342039, 673 | "c" 674 | ], 675 | [ 676 | 0.216026, 677 | "e" 678 | ], 679 | [ 680 | 0.190381, 681 | "d" 682 | ], 683 | [ 684 | 0.151751, 685 | " " 686 | ], 687 | [ 688 | 0.384722, 689 | "t" 690 | ], 691 | [ 692 | 0.079744, 693 | "i" 694 | ], 695 | [ 696 | 0.138615, 697 | "l" 698 | ], 699 | [ 700 | 0.184238, 701 | "d" 702 | ], 703 | [ 704 | 0.209614, 705 | "e" 706 | ], 707 | [ 708 | 0.134926, 709 | " " 710 | ], 711 | [ 712 | 0.306113, 713 | "e" 714 | ], 715 | [ 716 | 0.239424, 717 | "x" 718 | ], 719 | [ 720 | 0.085048, 721 | "p" 722 | ], 723 | [ 724 | 0.195788, 725 | "a" 726 | ], 727 | [ 728 | 0.365517, 729 | "n" 730 | ], 731 | [ 732 | 0.293982, 733 | "s" 734 | ], 735 | [ 736 | 0.106408, 737 | "i" 738 | ], 739 | [ 740 | 0.063334, 741 | "o" 742 | ], 743 | [ 744 | 0.117276, 745 | "n" 746 | ], 747 | [ 748 | 0.5, 749 | "\r\n" 750 | ], 751 | [ 752 | 0.010063, 753 | "\u001b[31mExit code: 130\r\n\r\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 754 | ], 755 | [ 756 | 0.5, 757 | "p" 758 | ], 759 | [ 760 | 0.112113, 761 | "u" 762 | ], 763 | [ 764 | 0.169547, 765 | "s" 766 | ], 767 | [ 768 | 0.085307, 769 | "h" 770 | ], 771 | [ 772 | 0.5, 773 | "d" 774 | ], 775 | [ 776 | 0.111871, 777 | " " 778 | ], 779 | [ 780 | 0.187359, 781 | "/" 782 | ], 783 | [ 784 | 0.470093, 785 | "\r\n/ /tmp/demo\r\n" 786 | ], 787 | [ 788 | 0.009983, 789 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 790 | ], 791 | [ 792 | 0.5, 793 | "l" 794 | ], 795 | [ 796 | 0.122315, 797 | "s" 798 | ], 799 | [ 800 | 0.106214, 801 | " " 802 | ], 803 | [ 804 | 0.416945, 805 | "~" 806 | ], 807 | [ 808 | 0.5, 809 | "1" 810 | ], 811 | [ 812 | 0.101755, 813 | "/" 814 | ], 815 | [ 816 | 0.5, 817 | "u" 818 | ], 819 | [ 820 | 0.5, 821 | "/" 822 | ], 823 | [ 824 | 0.143321, 825 | "s" 826 | ], 827 | [ 828 | 0.107238, 829 | "/" 830 | ], 831 | [ 832 | 0.383921, 833 | "a" 834 | ], 835 | [ 836 | 0.084982, 837 | "p" 838 | ], 839 | [ 840 | 0.157185, 841 | "p" 842 | ], 843 | [ 844 | 0.27639, 845 | "\r\n" 846 | ], 847 | [ 848 | 0.000539, 849 | "\u001b[01;35m/tmp/demo/usr/share/app\u001b[0m\u001b[K-file\u001b[0m\u001b[K \u001b[01;35m/tmp/demo/usr/share/app\u001b[0m\u001b[K\u001b[01;34m-second-dir\u001b[0m\u001b[K\r\n\u001b[01;35m/tmp/demo/usr/share/app\u001b[0m\u001b[K\u001b[01;34mlications\u001b[0m\u001b[K \r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mls /tmp/demo/usr/share/app\u0007" 850 | ], 851 | [ 852 | 0.5, 853 | "-file" 854 | ], 855 | [ 856 | 0.5, 857 | "\b\b\b\b\blications" 858 | ], 859 | [ 860 | 0.5, 861 | "\r\n" 862 | ], 863 | [ 864 | 0.002593, 865 | "app-one app-two\r\n" 866 | ], 867 | [ 868 | 0.010324, 869 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 870 | ], 871 | [ 872 | 0.5, 873 | "p" 874 | ], 875 | [ 876 | 0.112249, 877 | "o" 878 | ], 879 | [ 880 | 0.264884, 881 | "p" 882 | ], 883 | [ 884 | 0.422347, 885 | "d" 886 | ], 887 | [ 888 | 0.463701, 889 | "\r\n/tmp/demo\r\n" 890 | ], 891 | [ 892 | 0.010508, 893 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n" 894 | ], 895 | [ 896 | 0.000485, 897 | "\u001b[1;33m$ \u001b[0m" 898 | ], 899 | [ 900 | 0.5, 901 | "#" 902 | ], 903 | [ 904 | 0.5, 905 | " " 906 | ], 907 | [ 908 | 0.095667, 909 | "s" 910 | ], 911 | [ 912 | 0.167514, 913 | "o" 914 | ], 915 | [ 916 | 0.467666, 917 | "\b\u001b[K" 918 | ], 919 | [ 920 | 0.239549, 921 | "u" 922 | ], 923 | [ 924 | 0.232154, 925 | "p" 926 | ], 927 | [ 928 | 0.188703, 929 | "p" 930 | ], 931 | [ 932 | 0.244714, 933 | "o" 934 | ], 935 | [ 936 | 0.182331, 937 | "r" 938 | ], 939 | [ 940 | 0.228102, 941 | "t" 942 | ], 943 | [ 944 | 0.132773, 945 | " " 946 | ], 947 | [ 948 | 0.194277, 949 | "f" 950 | ], 951 | [ 952 | 0.456111, 953 | "o" 954 | ], 955 | [ 956 | 0.09077, 957 | "r" 958 | ], 959 | [ 960 | 0.141492, 961 | " " 962 | ], 963 | [ 964 | 0.5, 965 | "s" 966 | ], 967 | [ 968 | 0.122377, 969 | "p" 970 | ], 971 | [ 972 | 0.101008, 973 | "e" 974 | ], 975 | [ 976 | 0.226812, 977 | "c" 978 | ], 979 | [ 980 | 0.058341, 981 | "i" 982 | ], 983 | [ 984 | 0.235975, 985 | "a" 986 | ], 987 | [ 988 | 0.111411, 989 | "l" 990 | ], 991 | [ 992 | 0.181091, 993 | " " 994 | ], 995 | [ 996 | 0.5, 997 | "c" 998 | ], 999 | [ 1000 | 0.128092, 1001 | "h" 1002 | ], 1003 | [ 1004 | 0.132078, 1005 | "a" 1006 | ], 1007 | [ 1008 | 0.327665, 1009 | "r" 1010 | ], 1011 | [ 1012 | 0.11692, 1013 | "a" 1014 | ], 1015 | [ 1016 | 0.5, 1017 | "c" 1018 | ], 1019 | [ 1020 | 0.210184, 1021 | "t" 1022 | ], 1023 | [ 1024 | 0.138682, 1025 | "e" 1026 | ], 1027 | [ 1028 | 0.438403, 1029 | "r" 1030 | ], 1031 | [ 1032 | 0.282047, 1033 | "s" 1034 | ], 1035 | [ 1036 | 0.361003, 1037 | " " 1038 | ], 1039 | [ 1040 | 0.079756, 1041 | "i" 1042 | ], 1043 | [ 1044 | 0.172539, 1045 | "n" 1046 | ], 1047 | [ 1048 | 0.096372, 1049 | " " 1050 | ], 1051 | [ 1052 | 0.127203, 1053 | "f" 1054 | ], 1055 | [ 1056 | 0.106727, 1057 | "i" 1058 | ], 1059 | [ 1060 | 0.117491, 1061 | "l" 1062 | ], 1063 | [ 1064 | 0.121911, 1065 | "e" 1066 | ], 1067 | [ 1068 | 0.463106, 1069 | "p" 1070 | ], 1071 | [ 1072 | 0.095849, 1073 | "a" 1074 | ], 1075 | [ 1076 | 0.272846, 1077 | "t" 1078 | ], 1079 | [ 1080 | 0.084875, 1081 | "h" 1082 | ], 1083 | [ 1084 | 0.5, 1085 | "\r\n" 1086 | ], 1087 | [ 1088 | 0.009932, 1089 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1090 | ], 1091 | [ 1092 | 0.5, 1093 | "u" 1094 | ], 1095 | [ 1096 | 0.438035, 1097 | "\b\u001b[K" 1098 | ], 1099 | [ 1100 | 0.214339, 1101 | "l" 1102 | ], 1103 | [ 1104 | 0.084679, 1105 | "s" 1106 | ], 1107 | [ 1108 | 0.152774, 1109 | " " 1110 | ], 1111 | [ 1112 | 0.5, 1113 | "u" 1114 | ], 1115 | [ 1116 | 0.231693, 1117 | "/" 1118 | ], 1119 | [ 1120 | 0.44381, 1121 | "s" 1122 | ], 1123 | [ 1124 | 0.106446, 1125 | "/" 1126 | ], 1127 | [ 1128 | 0.332864, 1129 | "a" 1130 | ], 1131 | [ 1132 | 0.391813, 1133 | "\r\n" 1134 | ], 1135 | [ 1136 | 0.000556, 1137 | "\u001b[01;35musr/share/a\u001b[0m\u001b[K\\ directory\\ with\\ spaces\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpplications\u001b[0m\u001b[K\r\n\u001b[01;35musr/share/a\u001b[0m\u001b[Kpp-file\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpp-second-dir\u001b[0m\u001b[K\r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mls usr/share/a\u0007" 1138 | ], 1139 | [ 1140 | 0.5, 1141 | "\\ directory\\ with\\ spaces" 1142 | ], 1143 | [ 1144 | 0.5, 1145 | "\r\n" 1146 | ], 1147 | [ 1148 | 0.012551, 1149 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1150 | ], 1151 | [ 1152 | 0.5, 1153 | "#" 1154 | ], 1155 | [ 1156 | 0.477597, 1157 | " " 1158 | ], 1159 | [ 1160 | 0.201583, 1161 | "a" 1162 | ], 1163 | [ 1164 | 0.179791, 1165 | "n" 1166 | ], 1167 | [ 1168 | 0.080404, 1169 | "d" 1170 | ], 1171 | [ 1172 | 0.137932, 1173 | " " 1174 | ], 1175 | [ 1176 | 0.318577, 1177 | "f" 1178 | ], 1179 | [ 1180 | 0.123193, 1181 | "o" 1182 | ], 1183 | [ 1184 | 0.152783, 1185 | "r" 1186 | ], 1187 | [ 1188 | 0.090883, 1189 | " " 1190 | ], 1191 | [ 1192 | 0.5, 1193 | "o" 1194 | ], 1195 | [ 1196 | 0.121936, 1197 | "p" 1198 | ], 1199 | [ 1200 | 0.190044, 1201 | "e" 1202 | ], 1203 | [ 1204 | 0.111734, 1205 | "n" 1206 | ], 1207 | [ 1208 | 0.069761, 1209 | "e" 1210 | ], 1211 | [ 1212 | 0.248866, 1213 | "d" 1214 | ], 1215 | [ 1216 | 0.401851, 1217 | " " 1218 | ], 1219 | [ 1220 | 0.5, 1221 | "q" 1222 | ], 1223 | [ 1224 | 0.085925, 1225 | "u" 1226 | ], 1227 | [ 1228 | 0.113538, 1229 | "o" 1230 | ], 1231 | [ 1232 | 0.234887, 1233 | "t" 1234 | ], 1235 | [ 1236 | 0.106866, 1237 | "e" 1238 | ], 1239 | [ 1240 | 0.299966, 1241 | "s" 1242 | ], 1243 | [ 1244 | 0.5, 1245 | "\r\n" 1246 | ], 1247 | [ 1248 | 0.009794, 1249 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1250 | ], 1251 | [ 1252 | 0.396338, 1253 | "l" 1254 | ], 1255 | [ 1256 | 0.09032, 1257 | "s" 1258 | ], 1259 | [ 1260 | 0.132933, 1261 | " " 1262 | ], 1263 | [ 1264 | 0.5, 1265 | "\"" 1266 | ], 1267 | [ 1268 | 0.393302, 1269 | "u" 1270 | ], 1271 | [ 1272 | 0.5, 1273 | "/" 1274 | ], 1275 | [ 1276 | 0.116551, 1277 | "s" 1278 | ], 1279 | [ 1280 | 0.107433, 1281 | "/" 1282 | ], 1283 | [ 1284 | 0.5, 1285 | "a" 1286 | ], 1287 | [ 1288 | 0.479516, 1289 | "\r\n" 1290 | ], 1291 | [ 1292 | 0.00048, 1293 | "\u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34m directory with spaces\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpplications\u001b[0m\u001b[K\r\n\u001b[01;35musr/share/a\u001b[0m\u001b[Kpp-file\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpp-second-dir\u001b[0m\u001b[K\r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mls \"usr/share/a\u0007" 1294 | ], 1295 | [ 1296 | 0.5, 1297 | " directory with spaces\"" 1298 | ], 1299 | [ 1300 | 0.5, 1301 | "\r\n" 1302 | ], 1303 | [ 1304 | 0.012889, 1305 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1306 | ], 1307 | [ 1308 | 0.5, 1309 | "#" 1310 | ], 1311 | [ 1312 | 0.5, 1313 | " " 1314 | ], 1315 | [ 1316 | 0.5, 1317 | "o" 1318 | ], 1319 | [ 1320 | 0.079658, 1321 | "r" 1322 | ], 1323 | [ 1324 | 0.432521, 1325 | " " 1326 | ], 1327 | [ 1328 | 0.193025, 1329 | "o" 1330 | ], 1331 | [ 1332 | 0.121874, 1333 | "t" 1334 | ], 1335 | [ 1336 | 0.106731, 1337 | "h" 1338 | ], 1339 | [ 1340 | 0.10626, 1341 | "e" 1342 | ], 1343 | [ 1344 | 0.259536, 1345 | "r" 1346 | ], 1347 | [ 1348 | 0.199472, 1349 | " " 1350 | ], 1351 | [ 1352 | 0.5, 1353 | "q" 1354 | ], 1355 | [ 1356 | 0.069652, 1357 | "u" 1358 | ], 1359 | [ 1360 | 0.106409, 1361 | "o" 1362 | ], 1363 | [ 1364 | 0.360847, 1365 | "t" 1366 | ], 1367 | [ 1368 | 0.138188, 1369 | "e" 1370 | ], 1371 | [ 1372 | 0.301891, 1373 | "s" 1374 | ], 1375 | [ 1376 | 0.5, 1377 | "\r\n" 1378 | ], 1379 | [ 1380 | 0.009974, 1381 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n" 1382 | ], 1383 | [ 1384 | 0.000534, 1385 | "\u001b[1;33m$ \u001b[0m" 1386 | ], 1387 | [ 1388 | 0.5, 1389 | "l" 1390 | ], 1391 | [ 1392 | 0.085135, 1393 | "s" 1394 | ], 1395 | [ 1396 | 0.148931, 1397 | " " 1398 | ], 1399 | [ 1400 | 0.30214, 1401 | "'" 1402 | ], 1403 | [ 1404 | 0.448884, 1405 | "u" 1406 | ], 1407 | [ 1408 | 0.384172, 1409 | "/" 1410 | ], 1411 | [ 1412 | 0.117025, 1413 | "s" 1414 | ], 1415 | [ 1416 | 0.101481, 1417 | "/" 1418 | ], 1419 | [ 1420 | 0.5, 1421 | "a" 1422 | ], 1423 | [ 1424 | 0.5, 1425 | "\r\n" 1426 | ], 1427 | [ 1428 | 0.000606, 1429 | "\u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34m directory with spaces\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpplications\u001b[0m\u001b[K\r\n\u001b[01;35musr/share/a\u001b[0m\u001b[Kpp-file\u001b[0m\u001b[K \u001b[01;35musr/share/a\u001b[0m\u001b[K\u001b[01;34mpp-second-dir\u001b[0m\u001b[K\r\n\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0mls 'usr/share/a\u0007" 1430 | ], 1431 | [ 1432 | 0.452632, 1433 | " directory with spaces'" 1434 | ], 1435 | [ 1436 | 0.5, 1437 | "\r\n" 1438 | ], 1439 | [ 1440 | 0.012026, 1441 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1442 | ], 1443 | [ 1444 | 0.5, 1445 | "#" 1446 | ], 1447 | [ 1448 | 0.5, 1449 | " " 1450 | ], 1451 | [ 1452 | 0.229181, 1453 | "T" 1454 | ], 1455 | [ 1456 | 0.189297, 1457 | "h" 1458 | ], 1459 | [ 1460 | 0.20869, 1461 | "a" 1462 | ], 1463 | [ 1464 | 0.122408, 1465 | "n" 1466 | ], 1467 | [ 1468 | 0.212699, 1469 | "k" 1470 | ], 1471 | [ 1472 | 0.276885, 1473 | " " 1474 | ], 1475 | [ 1476 | 0.17898, 1477 | "y" 1478 | ], 1479 | [ 1480 | 0.05829, 1481 | "o" 1482 | ], 1483 | [ 1484 | 0.19274, 1485 | "u" 1486 | ], 1487 | [ 1488 | 0.413569, 1489 | "!" 1490 | ], 1491 | [ 1492 | 0.5, 1493 | "\r\n" 1494 | ], 1495 | [ 1496 | 0.010068, 1497 | "\u001b[31m\u001b[0m\r\r\n\r\r\n\u001b[1;33m[user@laptopmini]\u001b[0m \u001b[32m/tmp/demo/\u001b[0m\u001b[33m\u001b[0m\u001b[34m (2)\u001b[0m\r\r\n\u001b[1;33m$ \u001b[0m" 1498 | ] 1499 | ], 1500 | "duration": 89.021292, 1501 | "width": 84, 1502 | "env": { 1503 | "TERM": "screen.xterm-new", 1504 | "SHELL": "/bin/bash" 1505 | } 1506 | } 1507 | --------------------------------------------------------------------------------