fish shell

今天在hacker news上闲逛,又看到有人推销fish。心想马上就2022年了,不如换个shell耍耍。 其实早在2013年就接触过fish,那个时候自己比较菜,工作的时候很多bash脚本在fish上都不能使用,所以就放弃fish。 安装 安装fish 1 2 3 sudo port install fish sudo chpass -s /opt/local/bin/fish ${USER} cat /etc/shells 退出zsh,重启terminal 安装插件 oh-my-fish / fisher 1 2 3 4 5 6 curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install > install fish install --path=~/.local/share/omf --config=~/.config/omf # 可能出现 https://git.io无法访问的问题 curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher autojump/ j 1 2 3 4 5 6 7 8 sudo port uninstall autojump git clone https://github.com/wting/autojump.git cd autojump/ ./install.py cd repo/github/autojump/ vi .config/fish/config.fish j home nvm 1 2 3 4 5 6 7 8 sudo port uninstall nvm fisher install jorgebucaran/nvm.fish nvm install latest nvm list nvm --version #nvm use v17.1.0 # Now using Node v17.1.0 (npm 8.1.2) ~/.local/share/nvm/v17.1.0/bin/node node --version fisher plugins 1 2 3 4 5 fisher install IlanCosman/tide@v5 fisher install PatrickF1/fzf.fish fisher install franciscolourenco/done 配置 PATH 1 2 3 echo $PATH fish_add_path /Users/r/go/bin fish_add_path /opt/local/bin alias 默认ls命令对文件和目录没有做颜色的区分,可以使用alias ls='ls -G'加上颜色选项:) ...

November 26, 2021 · datewu

bash简介

本文会不定期更新 :) set 可以使用set命令改变shell脚本默认的执行流程。 比如 set -e 可以使得shell脚本遇到某一条命令出错( echo $? 不为0)时立即退出执行。 1 2 3 4 #/bin/bash set -e false echo you cannot see me, unless you comment out the 'set -e' flag, haha set详细文档 du 1 2 ❯ du -sh Downloads 4.1G Downloads wiki rm 1 rm $0 # 删除当前文件 for cleanup job nohup 在后台执行当前命令: 1 nohup /usr/sbin/script.sh & 默认情况下,进程是前台进程,这时就把Shell给占据了,我们无法进行其他操作,对于那些没有交互的进程, 我们希望将其在后台启动,可以在启动参数的时候加一个’&‘实现这个目的。 1 2 3 4 5 ❯ sleep 5 & [1] 34769 ✦ ❯ [1] + 34769 done sleep 5 ✦ ❯ 进程切换到后台的时候,我们把它称为job。切换到后台时会输出相关job信息,上面&的输出 [1] 34769 : [1]表示job ID 是1,11319表示进程ID是34769。切换到后台的进程,仍然可以用ps命令查看。 ...

November 17, 2021 · datewu

事件驱动

在shell脚本里使用mkfifo命令创建named pipes可以实现简单的事件驱动, 避免poll(轮询)带来的时延(not real-time)和资源消耗的问题。 mkfifo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ❯ man mkfifo | head -n 12 MKFIFO(1) General Commands Manual MKFIFO(1) NAME mkfifo – make fifos SYNOPSIS mkfifo [-m mode] fifo_name ... DESCRIPTION mkfifo creates the fifos requested, in the order specified. By default, the resulting fifos have mode 0666 (rw-rw-rw-), limited by the current umask(2). ~ consumer 消费者以blocked的状态监听事件的发生,然后handle: ...

June 27, 2018 · datewu

脚本注入

使用opkg安装软件时,常常需要对候软件包进行初始化或者自定义化操作,这种开发需求一般写给shell脚本就可以对付了。 现在的问题是当这些脚本多了之后,原作者也不愿意修改安装包,我们怎么分发这些自定义的脚本,能不能把自定义的这些脚本编译到opkg包里? 位置 把本地的shell脚本放在openwert 仓库的这个目录,编译openwrt的时候就会被打包到对应opkg二进制文件中: 1 2 /barrier_breaker/package/package-abc # package makefile文件所在 package-abc/files # shell脚本放置目录 步骤 修改Makefile 在package目录下任意找一个package目录,比如chinadns, 然后修改Makefile文件。 在install语句后添加 : 1 $(INSTALL_BIN) ./files/your_script.sh $(1)/etc/config/your_script.sh 放置脚本 将脚本your_script.sh放置在files目录下; 选择opkg 在make menuconfig 图像界面中选择修改过的包(chinadns) 附 package 和注入文件相关的部分makefile代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 ## include $(TOPDIR)/rules.mk PKG_NAME:=xxx PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://github.com/xxx/releases/download/v$(PKG_VERSION) PKG_MD5SUM:=f772a750580243cfxcsfd2xc39d7b9171b1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk ## define Package/xxx SECTION:=net CATEGORY:=Network TITLE:=xxx endef ### define Package/xxx/description button haha upgrade. endef ### #define Package/xxx/conffiles #/etc/config/system #/etc/hotplug.d/button/00-button #endef ### define Package/wps_button/install #$(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/xxx $(1)/etc/config/xxx #$(INSTALL_DATA) ./files/system.conf $(1)/etc/config/system endef ### $(eval $(call BuildPackage,xxx)) ##

June 18, 2015 · datewu

字符串

运维人员/系统管理员每天要在终端敲入大量命令,也要修改查看大量文本配置文件,日志信息。 甚至可以夸张一点说Linux/Unix system admin的全部工作就是和字符串打交道。 binary 大家都知道文本文件是字符串组成的,其实二进制文件里面其实也包含了很多字符串: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ➜ infra-api git:(dev) file infra-api infra-api: Mach-O 64-bit executable x86_64 ➜ infra-api git:(dev) strings infra-api | head flag hash mime path sort sync time *int AAAA Addr ➜ infra-api git:(dev) 命令 收集一些常用的shell 字符串操作命令 cut 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ❯ tldr cut Cut out fields from stdin or files. More information: https://www.gnu.org/software/coreutils/cut. - Cut out the first sixteen characters of each line of stdin: cut -c 1-16 - Cut out the first sixteen characters of each line of the given files: cut -c 1-16 file - Cut out everything from the 3rd character to the end of each line: cut -c 3- - Cut out the fifth field of each line, using a colon as a field delimiter (default delimiter is tab): cut -d':' -f5 - Cut out the 2nd and 10th fields of each line, using a semicolon as a delimiter: cut -d';' -f2,10 - Cut out the fields 3 through to the end of each line, using a space as a delimiter: cut -d' ' -f3- cat/less cat,主要有三大使用场景: ...

May 17, 2015 · datewu