bash-completion

Reference git stash by number without stash@{i}

一笑奈何 提交于 2020-02-23 06:46:05
问题 I'm using git stashes extensively. Sometimes it becomes annoying to type out stash@{3} when, at first glance, a simple 3 should suffice. Is it possible to use the shorter reference somehow? I know a solution with shell aliases. Making an alias like sshow = "!f { git stash show @{$@}; }; f" allows using git sshow 1 . It even allows passing additional arguments to git stash show if $@ is expanded properly. However, in this case git autocomplete does not work: when git stash show stash@{0} --

Reference git stash by number without stash@{i}

ⅰ亾dé卋堺 提交于 2020-02-23 06:45:29
问题 I'm using git stashes extensively. Sometimes it becomes annoying to type out stash@{3} when, at first glance, a simple 3 should suffice. Is it possible to use the shorter reference somehow? I know a solution with shell aliases. Making an alias like sshow = "!f { git stash show @{$@}; }; f" allows using git sshow 1 . It even allows passing additional arguments to git stash show if $@ is expanded properly. However, in this case git autocomplete does not work: when git stash show stash@{0} --

Reference git stash by number without stash@{i}

此生再无相见时 提交于 2020-02-23 06:45:16
问题 I'm using git stashes extensively. Sometimes it becomes annoying to type out stash@{3} when, at first glance, a simple 3 should suffice. Is it possible to use the shorter reference somehow? I know a solution with shell aliases. Making an alias like sshow = "!f { git stash show @{$@}; }; f" allows using git sshow 1 . It even allows passing additional arguments to git stash show if $@ is expanded properly. However, in this case git autocomplete does not work: when git stash show stash@{0} --

bash autocompletion with file names

∥☆過路亽.° 提交于 2020-01-04 01:06:42
问题 I can't get a simple bash autocompletion function to work. I need to autocomplete file names from a predefined directory so it will look like this: $ cmd log<TAB><TAB> file1.log file2.log file3.log Where files are from /var/log/app . 回答1: I don't see the point of using ls when the shell can list files just fine by itself, so here's one using just the shell. _cmd() { local files=("/var/log/app/$2"*) [[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]##*/}" ) } complete -F _cmd cmd 回答2: I found

shell介绍、history历史命令及配置文件、tab补全、通配符和输出重定向

孤者浪人 提交于 2019-12-30 12:36:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 10月11日任务 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 8.1 shell介绍 什么是shell shell是一个命令解释器,提供用户和机器之间的交互 支持特定语法,比如逻辑判断、循环 每个用户都可以有自己特定的shell CentOS7默认shell为bash(Bourne Agin Shell) 还有zsh/ksh等 8.2 命令历史 history命令 .bash_history 最大1000条 变量HISTSIZE /etc/prefile中修改 #vim /etc/prefile 来修改变量HISTSIZE值 HISTTIMEFORMAT="%Y/%m/%d%H:%M:%S" 永久保存 chattr +a ~/.bash_history !! #表示上一条命令 !n #表示第n条命令 !word #表示执行最后一条word命令 #查看历史命令 [root@centos6 ~]# history #历史命令变量 [root@centos6 ~]# echo $HISTSIZE 1000 #history -c清空内存中的命令历史,但不能修改配置文件 .bash_history里的内容 [root@centos6 ~]# history

23. shell介绍、历史 命令补全和别名 通配符 输入输出重定向

拜拜、爱过 提交于 2019-12-30 12:33:49
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 8.1 shell介绍: shell是一个命令解释器,提供用户与机器之间的交交互 支持特定语法,不如逻辑变换、循环 每个用户都可以有自己特定的shell centos7默认shell为bash(Bourne Agin Shell) 还有zsh、ksh等 可以看一下有没有zsh ksh [root @localhost ~]# yum list |grep zsh zsh.x86_64 5.0.2-28.el7 @base autojump-zsh.noarch 22.3.0-3.el7 epel zsh-html.x86_64 5.0.2-28.el7 base zsh-lovers.noarch 0.9.0-1.el7 epel [root @localhost ~]# yum list |grep ksh ksh.x86_64 20120801-137.el7 base mksh.x86_64 46-8.el7 base python-XStatic-Rickshaw.noarch 1.5.0.0-4.el7 epel python-moksha-common.noarch 1.2.3-2.el7

shell介绍-历史命令-通配符-重定向

拜拜、爱过 提交于 2019-12-30 12:05:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> shell 是一个命令解释器,提供用户和机器之间的交互 支持语法:逻辑判断,循环 每个用户有自己特定的shell centos7默认bash:/bin/bash 还有zsh,ksh等 history /家目录/.bash_history文件保存输入过的命令历史 默认最大记录1000条,可由环境变量HISTSIZE进行更改,或在/etc/profile文件修改对应值 命令历史存在于内存,当正常退出终端后才会保存到.bash_history文件里 history -c 清空内存里的命令历史,不会清空.bash_history文件 命令历史添加命令执行的时间:修改环境变量HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " (默认无此变量,或者="%F %T ");将变量赋值添加到.bash_history 永久保存历史文件:chattr +a ~/.bash_history !n:n为数字,执行命令历史中第n条命令 !xxx:命令历史从后往前执行第一次匹配到的以xxx开头的命令 [tab]键敲一下可补全命令名称,或路径、文件名称。 [tab]键敲两下可列出所有待补全的项 安装bash-completion可实现命令参数补全 保存alsia别名系统文件:~/.bashrc;/etc/profile

How to reuse rostopic's completion function for completing a custom bash function?

混江龙づ霸主 提交于 2019-12-24 21:14:14
问题 Defined bash function rte() : $ function rte(){ rostopic echo $@ ; }; and attempted to use rostopic 's completion function $ complete -p rostopic complete -F _roscomplete_rostopic rostopic via the command: $ complete -F _roscomplete_rostopic rte The above setting can be verified as follows: $ complete -p rte complete -F _roscomplete_rostopic rte However, rte <partial input><tab> does not offer completions. Question: How to get rte() to use rostopic 's completion? I guess when rte() 's

Is it possible to display some help message when showing autocomplete candidates?

有些话、适合烂在心里 提交于 2019-12-22 11:43:10
问题 Some commands have many -x ( x can be any English letter) options and it's some times difficult to remember all of their meanings. I can use bash's compgen -W '-a -b -c' to show possible options and I'm wondering if it's possible to also show some help message. Like this: bash# foo -<TAB><TAB> -a: This is option a -b: This is option b -C: This is option c bash# 回答1: I ever did something similar to map some of curl 's single char options (like -x ) to GNU style --long-option s. This is how it

Unit Test for Bash completion script

穿精又带淫゛_ 提交于 2019-12-21 04:01:06
问题 I would like to write a Unit Test for a (rather complex) Bash completion script, preferrably with Python - just something that gets the values of a Bash completion programmatically. The test should look like this: def test_completion(): # trigger_completion should return what a user should get on triggering # Bash completion like this: 'pbt createkvm<TAB>' assert trigger_completion('pbt createkvm') == "module1 module2 module3" How can I simulate Bash completion programmatically to check the