好用的shell命令行: fish的配置
fish的可视化配置命令:
$ fish_config
fish 很好的资源列表:
https://github.com/JorgeBucaran/awesome-fish
其配置文件夹为 ~/.config/fish。
1、要设置环境变量,在配置文件夹里新建 config.fish 文件,它会作为fish 启动时的加载文件,相当与bash的.bashrc,然后在里面配置环境变量,其环境变量配置方法与bash不同,格式如下:
# There are three kinds of variables in fish: universal, global and local variables.
# Universal variables are shared between all fish sessions a user is running on one computer.
# Global variables are specific to the current fish session, but are not associated with any
# specific block scope, and will never be erased unless the user explicitly requests it using set -e.
# Local variables are specific to the current fish session, and associated with a specific block of
# commands, and is automatically erased when a specific block goes out of scope.
# A block of commands is a series of commands that begins with one of the commands for, while , if, function,
# begin or switch, and ends with the command end.
# The user can specify that a variable should have either global or local scope using the -g/--global or -l/--local switches. # Variables can be explicitly set to be universal with the -U or --universal switch,
# global with the -g or --global switch, or local with the -l or --local switch. set -x JAVA_HOME /home/hzh/hzh/soft/jdk
set -x JRE_HOME {$JAVA_HOME}/jre
# 按照bash风格用:来分割多个值,但在fish中PATH不能用:来分割,必须用空格分割
set -x CLASSPATH .:{$JAVA_HOME}/lib:{$JRE_HOME}/lib
set -x PATH {$JAVA_HOME}/bin {$PATH} set -x ANDROID_HOME /home/zhou/android/android_adt/sdk
set -x PATH {$PATH} {$ANDROID_HOME}/build-tools/22.0.
set -x PATH {$PATH} {$ANDROID_HOME}/platform-tools
set -x PATH {$PATH} {$ANDROID_HOME}/tools
set -x NDK_HOME /home/zhou/android/android_adt/ndk
set -x PATH {$PATH} {$NDK_HOME} set -x PATH {$PATH} /home/zhou/android/android_adt/eclipse set -x GRADLE_HOME /home/hzh/hzh/soft/gradle
set -x PATH {$PATH} {$GRADLE_HOME}/bin
# 设置局部变量,必须用空格分割name及value,不能象bash那样用=来赋值
set -l MAVEN_HOME '/home/hzh/hzh/soft/maven'
set -x PATH {$PATH} {$MAVEN_HOME}/bin set -x CATALINA_HOME /home/hzh/hzh/soft/tomcat
2、若要定义alias,但fish里没有alias这个说法,因此官方介绍用function来替代alias。具体是这样的,在配置文件夹里( ~/.config/fish/ )新建一个名为functions的文件夹(建完之后 ~/.config/fish/functions),此文件夹里存放你所定义的function,function名就是文件名,后缀为.fish, 在fish启动的时候,所有位于functions文件夹里的以后缀.fish结尾的函数都会被自动加载,这样就定义了一个alias。如:
functions/meld.fish:
function meld --description 'compare files'
/usr/bin/meld >/dev/null >& $argv
end
每个函数都必须带参数 $argv,这是shell传过来的参数。
上面的说法有误,fish有alias的,放到 config.fish 里,但是它也等价于函数,无法这后台运行:
# 下面这句可以后台运行,因为 xdg-open 本身就是后台运行的程序
alias hopen 'xdg-open 2>/dev/null'
3、有别与bash的`键,fish里采用括号来完成命令执行的功能:
在bash中,使用 ls `which ls` 可以显示 /bin/ls。 而在fish中,使用 ls (which ls) 可以显示 /bin/ls。 用 echo a(data)则输出: a2016年 09月 23日 星期五 15:49:18 CST。
4、bash中的ctrl+r的搜索历史命令的功能(不断按ctrl+r可以继续搜索),在fish中已经得到了很好的解决,你只需要键入你想搜索的历史命令中的某写字母,再按ctrl+p就能不断搜索历史命令。
5、fish的function不能运行在后台,即加 & 没什么用。
6、fish的prompt, 在functions目录加入文件 fish_prompt.fish ,其内容为:
# 其中的 (hostname) (prompt_pwd) 为shell命令, $USER 为环境变量, __fish_prompt_hostname 为临时变量
function fish_prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname)
end
set_color -o cyan
echo -n -s "$USER" @ "$__fish_prompt_hostname" ": "
set_color -o green
echo -n (prompt_pwd)
# 也可以用这个: echo -n ' $ '
echo -n " \$ "
set_color normal
end
7、去掉欢迎信息(greeting message), 在fishd.* 文件中,替换SET fish_greeting:*** 为 SET fish_greeting: 注意冒号。(如下文件只修改有注释的地方就可以了)
# This file is automatically generated by the fish.
# Do NOT edit it directly, your changes will be overwritten.
SET __fish_init_1_50_0:\x1d
SET fish_color_autosuggestion:\x1eyellow
# SET fish_color_command:005fd7\x1epurple
SET fish_color_command:ffff00\x1epurple\x1e--bold
SET fish_color_comment:red
SET fish_color_cwd:green
SET fish_color_cwd_root:red
SET fish_color_error:red\x1e\x2d\x2dbold
SET fish_color_escape:cyan
SET fish_color_history_current:cyan
SET fish_color_match:cyan
SET fish_color_normal:normal
SET fish_color_operator:cyan
# SET fish_color_param:00afff\x1ecyan
SET fish_color_param:00ff00\x1ecyan\x1e--bold
SET fish_color_quote:brown
SET fish_color_redirection:normal
SET fish_color_search_match:\x2d\x2dbackground\x3dpurple
SET fish_color_selection:\x2d\x2dbackground\x3dpurple
SET fish_color_valid_path:\x2d\x2dunderline
# SET fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell\x0aType\x20\x1b\x5b32mhelp\x1b\x5b30m\x1b\x28B\x1b\x5bm\x20for\x20instructions\x20on\x20how\x20to\x20use\x20fish
SET fish_greeting:
SET fish_key_bindings:fish_default_key_bindings
SET fish_pager_color_completion:normal
SET fish_pager_color_description:\x1eyellow
SET fish_pager_color_prefix:cyan
SET fish_pager_color_progress:cyan
8、fish种的 \x1e 是什么,其实就一个分隔符,它的定义为:
/** Character for separating two array elements. We use 30, i.e. the ascii record separator since that seems logical. */
#define ARRAY_SEP 0x1e /** String containing the character for separating two array elements */
#define ARRAY_SEP_STR L"\x1e"
测试结果:
# 数组 [a] [b]
$ set aaa (printf 'a\x1eb')
$ count $aaa
2
# 数组 [a\x1fb]
$ set aaa (printf 'a\x1fb')
$ count $aaa
很明显,它是一个数组的分隔符.
ubuntu下fish shell设置 256 color:
首先运行:
- tput colors -This will report how many colors your terminal is using.
- echo $TERM -This will tell you what terminal you are using.
- echo $COLORTERM -If you are using a gnome you should see gnome-terminal.
确保使用的是 xterm。
在终端点击菜单 编辑-》配置文件首选项, 再点“命令”tab, 然后勾选上“运行自定义命令而不是shell”,在里面敲入: env TERM=xterm-256color /usr/bin/fish
fish shell 的命令行语法:
Fish 的语法非常自然,一眼就能看懂。
if语句:
if grep fish /etc/shells
echo Found fish
else if grep bash /etc/shells
echo Found bash
else
echo Got nothing
end
switch语句:
switch (uname)
case Linux
echo Hi Tux!
case Darwin
echo Hi Hexley!
case FreeBSD NetBSD DragonFly
echo Hi Beastie!
case '*'
echo Hi, stranger!
end
while循环:
while true
echo "Loop forever"
end
for循环:
for file in *.txt
cp $file $file.bak
end
fish 的函数
Fish 的函数用来封装命令,或者为现有的命令起别名,可在配置文件夹里定义函数文件(文件名必须是函数名),或者在命令行直接定义函数:
function llss
ls -lhG $argv
end
上面代码定义了一个llss函数。命令行执行这个函数以后,就可以用llss命令替代ls -lhG。其中,变量$argv表示函数的参数,每个定义的函数都必须带这个参数,由fish负责参数值的传递。
下面是另一个例子:
function ls
command ls -hG $argv
end
上面的代码重新定义ls命令。注意,函数体内的ls之前,要加上command,否则会因为无限循环而报错。
下面是我自己写的一个较完整的fish函数示例:
function testecho
echo $argv[]
# $status 使用一次就会被清空,所有暂存它
set result $status
if [ -eq $result ]
echo command execute success
else
echo $result
echo command execute failed
return
end
# 下面的命令执行结果不为0,即执行不成功
SOME_ERROR_COMMAND
set result $status
if [ -eq $result ]
echo command execute success
else
echo $result
echo command execute failed
return
end sleep
echo $argv[]
end
fish 中对argv参数进行interate:
function sss
for a in $argv
set aa (math "$a+1")
myecho $a $aa
end
echo ""
for a in $argv[..-]
myecho $a $a+
end
end
其中 myecho 为:
function myecho
echo $argv[] $argv[]
end
对于单引号和双引号的使用请参照如下示例:
$ A=B\ C
$ echo '"$A"' # 最外面的是单引号, 输出结果: "$A"
$ echo "'$A'" # 最外面的是双引号, 输出结果: 'B C'
function vote_eosnameswaps --description 'vote each account of eosnameswaps'
echo "begin ..."
echo "" set CLEOS /home/hzh/github/eos_build/programs/cleos/cleos for each_voter in $argv[..-]
echo $each_voter
./cleos -v -u http://api.eosnewyork.io push action eosnameswaps vote '[ "p.eos","'$each_voter'" ]' -p $each_voter@active
sleep
end echo ""
echo "finished"
end
fish shell 读取文本文件然后将头尾的空字符去掉,替换中间所有2个及2个以上的连续空字符为一个空格,然后在分割成可以单独使用的元素:
function read-file-trim-split
for line in (cat /tmp/hzh)
set all "$all $line"
end
set all (string trim $all)
set all (string replace -ar "\\s{2,}" " " $all)
set all (string split " " $all)
echo $all
for word in $all
echo $word
end
end
fish shell 中的比较和数学运算:
function go
set d
while true
set d (math "$d * 1.1 + 0.003")
if math "$d > 117"
break
end
echo $d
end
end
fish 中的字符串比较,参数iterate, switch等:
function rm --description 'vote each account of eosnameswaps'
if test (count $argv) -lt
return
end # for a in $argv[..-]
# if test $a = "."
# echo "no"
# return
# end
# end for i in (seq (count $argv))
if test $argv[$i] = "."
echo "do not delete ./"
return
end
if test $argv[$i] = "./"
echo "do not delete ./"
return
end switch $argv[$i]
case "*..*"
echo "do not delete ../ or ../../ or ../file etc."
return
case "-*"
set argv[$i] ""
end
end # if test (count $argv) -lt -o "$argv[1]" = "--help"
# echo ""
# end echo "move it/them to trash."
gio trash $argv
end
好用的shell命令行: fish的配置的更多相关文章
- 几种在shell命令行中过滤adb logcat输出的方法
我们在Android开发中总能看到程序的log日志内容充满了屏幕,而真正对开发者有意义的信息被淹没在洪流之中,让开发者无所适从,严重影响开发效率.本文就具体介绍几种在shell命令行中过滤adblog ...
- 自学Linux Shell2.1-进入shell命令行
点击返回 自学Linux命令行与Shell脚本之路 2.1-进入shell命令行 进入文本命令行界面(CLI)两种方法: 控制台终端 图形化终端 1. 通过Linux控制台终端访问CLI 按下Ctrl ...
- Hadoop HDFS的shell(命令行客户端)操作实例
HDFS的shell(命令行客户端)操作实例 3.2 常用命令参数介绍 -help 功能:输出这个命令参数手册 -ls 功能:显示目录信息 示例: hadoop fs ...
- Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本
Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本 在 mac 或者 linux 系统中,我们的浏览器或者其他下载软件下载的文件全部都下载再 ~/Downloads/ 文 ...
- HDFS shell命令行常见操作
hadoop学习及实践笔记—— HDFS shell命令行常见操作 附:HDFS shell guide文档地址 http://hadoop.apache.org/docs/r2.5.2/hadoop ...
- Shell 命令行实现将一个站点页面全部下载到本地并替换其中链接的脚本
Shell 命令行实现将一个站点页面全部下载到本地并替换其中链接的脚本 不知道为什么,我总想用 Shell 脚本来实现把一个站点内容给下载下来.但是下载什么站点我确不知道.今天尝试了一下利用 curl ...
- Shell 命令行,实现对若干网站状态批量查询是否正常的脚本
Shell 命令行,实现对若干网站状态批量查询是否正常的脚本 如果你有比较多的网站,这些网站的运行状态是否正常则是一件需要关心的事情.但是逐一打开检查那简直是一件太糟心的事情了.所以,我想写一个 sh ...
- Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件
Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件 前面我写了一篇博文Shell 从日志文件中选择时间段内的日志输出到另一个文件,利用循环实现了我想要实现的内容. 但是用这个脚本的同 ...
- Shell 命令行统计 apache 网站日志访问IP以及IP归属地
Shell 命令行统计 apache 网站日志访问IP以及IP归属地 我的一个站点用 apache 服务跑着,积攒了很多的日志.我想用 shell 看看有哪些人访问过我的站点,并且他来自哪里. 因为日 ...
随机推荐
- SQL[连载3]sql的一些高级用法
SQL[连载3]sql的一些高级用法 SQL 高级教程 SQL SELECT TOP SQL SELECT TOP 子句 SELECT TOP 子句用于规定要返回的记录的数目. SELECT TOP ...
- 《OD学Hive》第六周20160730
一.Hive的JDBC连接 日志分析结果数据,存储在hive中 <property> <name>hive.server2.thrift.port</name> & ...
- jxl导入/导出excel
1.jxl导入/导出excel案例,黏贴即可运行 package junit.test; import java.io.File; import java.io.IOException; import ...
- Z-偏移量
使用Z-偏移量 在一个三维场景中,我们可以对共面的多边形使用z-偏移量来使它们不再共面.这项技术通常用于在场景中正确的显示阴影.例如,一堵墙上的阴影与这堵墙的深度值是相同的,如果我们先渲染了墙再来渲染 ...
- CentOS 安装 mono
1. 安装EPEL 2. 安装软件包 yum install bison gettext glib2 freetype fontconfig libpng libpng-devel libX11 li ...
- 关于android软键盘enter键的替换与事件监听
android软键盘事件监听enter键 软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有 normal,actionUnspecified,actionNo ...
- Ubuntu中文输入法的安装
Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu的中文系统中自带了中文输入法,通过Ctrl+S ...
- 【英语】Bingo口语笔记(76) - 不知如何应答的场景对话
- RAC 环境下参数文件(spfile)管理
RAC环境下,初始化参数文件与但实例下参数文件有些异同,主要表现在初始化参数可以为多个实例公用,也可以单独设置各个实例的初始化参数.对于那些非共用的初始化参数则必须要单独设置,而共用的则可以单独设置, ...
- 【转】 iOS开发之打包上传到App Store——(一)各种证书的理解
OK,有日子没写iOS开发的相关文章啦,主要是最近的精力都没在这上面,不过既然产品已经快要出来了,就有必要了解一下各种证书啥的(众所周知iOS的一堆证书可是很让人头大呀),最近确实被这个搞得头大,然后 ...