Skip to content

Commit

Permalink
添加打开/关闭 WIFI 功能
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnacy committed Jun 20, 2020
1 parent 5121415 commit 9a5425d
Show file tree
Hide file tree
Showing 26 changed files with 853 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ golang/pkg/
golang/bin/
golang/src/github.com/
golang/src/gopkg.in/

site/
Binary file added AEE5C04E-1C5F-4BBF-982B-B3B051538EEA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

## 复制常用命令

[常用命令](https://cmd.wxnacy.com)

<!-- ![cmds](https://github.com/wxnacy/image/blob/master/blog/alfred-cp.gif) -->
![t34KxS.gif](https://s1.ax1x.com/2020/06/01/t34KxS.gif)

Expand All @@ -32,3 +34,7 @@
# 查看磁盘使用情况

![t3WzZR.gif](https://s1.ax1x.com/2020/06/01/t3WzZR.gif)

# 开启/关闭 WIFI

![N1SOY9.gif](https://s1.ax1x.com/2020/06/20/N1SOY9.gif)
1 change: 0 additions & 1 deletion commands/cmd_docker
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ docker --version
docker version
# 查看 docker 详情
docker info

# 重新创建容器,并在后台运行
docker-compose up --force-recreate -d <name>
17 changes: 14 additions & 3 deletions commands/cmd_mac
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ defaults write com.apple.finder AppleShowAllFiles yes; killall Finder /System/Li
# 在文件夹不显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles no; killall Finder /System/Library/CoreServices/Finder.app

# 列出本机所有网络服务
networksetup -listallnetworkservices
# 清空DNS缓存
dscacheutil -flushcache

# 查看 Mac 系统内网 ip
ifconfig | grep en0 -A 3 | grep 'inet ' | awk '{print $2}'


# 系统软件总览
system_profiler SPSoftwareDataType

# 扫描附近可用 Wifi热点
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan

# 列出本机所有网络服务
networksetup -listallnetworkservices
# 关闭 Wifi
networksetup -setairportpower en0 off
# 启动 WIFI
networksetup -setairportpower en0 on
# 加入 WIFI
networksetup -setairportnetwork en0 <wifiname> <wifipsword>
57 changes: 57 additions & 0 deletions common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy([email protected])
# Description:
import os


def read_file(filename):
'''读取文件,并返回列表'''
with open(filename, 'r') as f:
return [o.strip('\n').strip(" ") for o in f.readlines()]

def read_cmd(filename):
'''
读取指令文件
'''
lines = read_file(filename)
lines = list(filter(lambda x: x, lines))
items = []
num = int(len(lines) / 2)
# 设置 icon
# 查找是否存在如下对应文件
# ./commands/cmd_{category}
# ./icon/{category}.png
cmd_name = os.path.basename(filename).split("_")[1]
icon = './icon.png'
cmd_icon_path = './icon/{}.png'.format(cmd_name)
if os.path.exists(cmd_icon_path):
icon = cmd_icon_path
for i in range(num):
item = dict(
title = lines[i * 2 + 1],
subtitle = lines[i * 2],
icon = icon,
valid = True,
)
item['arg'] = item['title']
items.append(item)
return items

# def read_json(filename):
# lines = []
# with open(filename, 'r') as f:
# lines = f.readlines()
# return json.loads(''.join(lines))

# def read_csv(filename):
# lines = []
# with open(filename, 'r') as f:
# lines = f.readlines()
# logging.info(lines)
# items = []
# for line in lines:
# ls = line.split(',')
# item = dict(title = ls[0].strip(" "), subtitle = ls[1].strip(" "))
# items.append(item)
# return items
78 changes: 78 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy([email protected])
# Description:

import os
import shutil
from common import read_cmd


YML = '''
site_name: 常用命令 # 站点名称
nav: # 文档目录
- 首页: index.md
{}
theme: readthedocs # 主题
'''

SOURCE_DIR = 'commands'
OUTPUT_DIR = 'docs'

def cmd2md(filename):
filepath = f'{SOURCE_DIR}/{filename}'
outfile = f'{OUTPUT_DIR}/{fmt_name(filename)}.md'
input_lines = read_cmd(filepath)
outlines = []
input_lines.sort(key = lambda x: x['title'])
title_key = set()
for line in input_lines:
title = line['subtitle']
cmd = line['title']
cmd_begin = ' '.join(cmd.split(" ")[:2])
if cmd_begin not in title_key:
title_key.add(cmd_begin)
outlines.append(f"## {cmd_begin}\n")

title = f'**{title[2:]}**\n'
cmd = f'```\n{cmd}\n```\n'

outlines.append(title)
outlines.append(cmd)
with open(outfile, 'w') as out:
out.writelines(outlines)

def fmt_name(name):
return name[4:]

def first_upper(name):
return name[0].upper() + name[1:]

def cmd2mdname(name):
return fmt_name(name) + '.md'

def main(dirname):
'''转换'''
files = os.listdir(dirname)
files.sort()
navs = []
for f in files:
if not f.startswith('cmd_'):
continue
cmd2md(f)
navs.append(f'- {first_upper(fmt_name(f))}: {fmt_name(f)}.md')

# shutil.move(f'{OUTPUT_DIR}/{cmd2mdname(files[0])}', f'{OUTPUT_DIR}/index.md')
nav = '\n '.join(navs)
# nav = nav.replace(cmd2mdname(files[0]), 'index.md')
yml = YML.format(nav)
with open('mkdocs.yml', 'w') as f:
f.write(yml)






if __name__ == "__main__":
main(SOURCE_DIR)
11 changes: 11 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Author: wxnacy([email protected])
# Description:

python convert.py

for file in `find site | grep '\.'`
do
outfile=`python -c "print('${file}'.replace('site/', ''))"`
ossutil cp -u $file oss://cmd-cn/${outfile}
done
63 changes: 63 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## docker --version
**查看版本**
```
docker --version
```
## docker build
**在当前目录创建镜像**
```
docker build -t <image-name> .
```
## docker container
**重启容器**
```
docker container restart <continer-name>
```
## docker exec
**在交互模式下进入容器,并进入 bash 环境**
```
docker exec -it <continer-name> /bin/bash
```
## docker image
**查看镜像列表**
```
docker image ls
```
## docker info
**查看 docker 详情**
```
docker info
```
## docker logs
**从最后 10 行开始实时查看日志**
```
docker logs -f --tail 10 <continer-name>
```
**从最后 10 行开始实时查看日志并过滤信息**
```
docker logs -f --tail 10 <continer-name> 2>&1 | grep <pattern>
```
## docker ps
**查看当前运行的进程列表**
```
docker ps
```
**查看所有进程列表**
```
docker ps -a
```
## docker restart
**重启所有服务**
```
docker restart `docker ps -a | awk '{print $1}'`
```
## docker version
**分别查看 client 和 server 的版本**
```
docker version
```
## docker-compose up
**重新创建容器,并在后台运行**
```
docker-compose up --force-recreate -d <name>
```
10 changes: 10 additions & 0 deletions docs/ffmpeg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## ffmpeg -i
**m3u8 转为 mp4**
```
ffmpeg -i <m3u8-file> -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 <mp4-file>
```
## ffmpeg -ss
**截取视频**
```
ffmpeg -ss <start> -t <end> -i <sourcefile> -vcodec copy -acodec copy <outputfile>
```
94 changes: 94 additions & 0 deletions docs/git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## git add
**将所有新增、修改的文件提交到索引中**
```
git add --ignore-removal .
```
**将所有新增、修改、删除的文件提交到索引中**
```
git add -A
```
**将所有修改、删除的文件提交到索引中**
```
git add -u
```
**将所有新增、修改、删除的文件提交到索引中**
```
git add .
```
## git blame
**查看文件每行的最后提交人和时间**
```
git blame <file>
```
**查看文件某个方法的最后提交人和时间**
```
git blame <file> -L :<funcname>
```
**查看文件行数范围内的最后提交人和时间**
```
git blame <file> -L <start>,<end>
```
## git branch
**查看所有分支,并显示版本信息**
```
git branch -v
```
## git checkout
**在本地创建远程分支**
```
git checkout -b <local-branch-name> origin/<remote-branch-name>
```
## git config
**全局模式缓存凭证 15 分钟**
```
git config --global credential.helper cache
```
**全局模式储存仓库凭证**
```
git config --global credential.helper store
```
**全局配置 git 邮箱**
```
git config --global user.email "[email protected]"
```
**全局配置 git 用户名**
```
git config --global user.name "your name"
```
**储存当前仓库凭证**
```
git config credential.helper store
```
## git fetch
**把远程分支拉到本地**
```
git fetch origin <branch_name>
```
## git init
**初始化当前目录为仓库**
```
git init
```
**创建 <repo_name> 仓库**
```
git init <repo_name>
```
## git log
**查看某人一段时间的提交记录,并显示详情**
```
git log --stat --author=<pattern> --after=<date> --before=<date>
```
## git merge
**撤销所有合并操作**
```
git merge --abort
```
## git pull
**拉取远程分支到本地**
```
git pull origin <branch-name>
```
**解决拉取项目到本地新仓库 fatal: refusing to merge unrelated histories 的问题**
```
git pull origin master --allow-unrelated-histories
```
Loading

0 comments on commit 9a5425d

Please sign in to comment.