小代码大作用:电脑开荒代码: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(36 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Windows | 某一天,你拿到了一台新电脑。或者,某一天,你的电脑系统崩溃了。你需要从头配置一套从前习惯的工具链,那么,以下这些小代码,非常有用。请在你理解用处、并自担风险的情况下使用。 | ||
== Windows 平台 == | |||
<syntaxhighlight lang="powershell" line> | <syntaxhighlight lang="powershell" line> | ||
# | # set-network-private.ps1 | ||
# | # 用于把公用网络改为私用网络,实现全屋共享。需以管理员权限运行:创建快捷方式,目标选本文件 | ||
Set-NetConnectionProfile -InterfaceAlias "以太网" -NetworkCategory Private | Set-NetConnectionProfile -InterfaceAlias "以太网" -NetworkCategory Private | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Debian | <syntaxhighlight lang="powershell" line> | ||
# shutdown.bat | |||
# 用于双击立即关机,省下从开始键点好几下才关机的工夫 | |||
@echo off | |||
shutdown.exe /s /t 00 | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# 右键创建快捷方式 | |||
# 在桌面双击就可以直达知乎 | |||
"C:\Program Files\Mozilla Firefox\firefox.exe" https://www.zhihu.com | |||
</syntaxhighlight> | |||
== Debian 平台 == | |||
<syntaxhighlight lang="bash" line> | |||
#!/bin/bash | |||
# 用于查找本目录下的文件,不区分文件名大小写。包含查找的关键字就可以查到。不想换行该怎么写呢?其实用变量参数$1即可,但两行更方便,符合直觉 | |||
read text | |||
find . -iname "*$text*" | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
#!/bin/bash | |||
# 用于比较文件 hash 值,确认文件是否为原版无更改 | |||
echo "input origin > " | |||
read origin | |||
echo "input local > " | |||
read local | |||
if [ ${origin,,} = ${local,,} ]; then | |||
echo "相等" | |||
else | |||
echo "有问题" | |||
fi | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
#!/bin/bash | |||
# 用于把在电脑上修改过的 rime 配置文件,推送到手机上,并自动重新部署手机端同文输入法 | |||
adb shell ime disable com.osfans.trime/.TrimeImeService | |||
adb shell am force-stop com.osfans.trime | |||
adb shell rm -r /sdcard/rime | |||
adb shell mkdir /sdcard/rime | |||
adb push /home/qlzq/500/Code/ok-trime/* /sdcard/rime | |||
adb shell ime enable com.osfans.trime/.TrimeImeService | |||
adb shell ime set com.osfans.trime/.TrimeImeService | |||
adb shell am broadcast -a com.osfans.trime.deploy | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
#!/bin/bash | |||
# 用于把电脑上的文件快速传到手机上的 01 文件夹 | |||
adb push $1 /sdcard/01 | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# .bashrc | |||
# 好用的 .bashrc 配置 | |||
# server | |||
alias s='ls -hl --ignore={Desktop,Documents,Music,Pictures,Public,Templates,Videos}' | |||
alias e='emacs --eval "(load-theme (quote adwaita))"' | |||
alias eq='emacs -Q --eval "(load-theme (quote adwaita))"' | |||
alias eb='emacs -Q --eval "(load-theme (quote adwaita))" /home/$USER/.bashrc' | |||
alias se='sudo emacs -Q --eval "(load-theme (quote adwaita))"' | |||
alias gwk='sudo emacs -Q --eval "(load-theme (quote adwaita))" /etc/mediawiki/LocalSettings.php' | |||
alias sb='source /home/$USER/.bashrc' | |||
alias as='apt search --names-only' | |||
alias ai='sudo apt install' | |||
alias au='sudo apt update' | |||
alias gc='git clone' | |||
alias rmd='rm -rf' | |||
eval "$(lua /home/$USER/Sources/z.lua/z.lua --init bash enhanced once)" | |||
# gui | |||
alias bye='systemctl suspend' | |||
alias sr='systemctl reboot' | |||
alias sp='systemctl poweroff' | |||
alias f='f.sh' | |||
alias gfw='gfw.sh' | |||
alias ff='firefox-esr -p >>/dev/null 2>&1 &' | |||
alias nl='firefox-esr -p Offline $1' | |||
alias sj='scrcpy -S >>/dev/null 2>&1 &' | |||
alias a2sj='a2sj.sh' | |||
alias gt='./gt.sh' | |||
alias p3='python3' | |||
alias tl='sudo tldr' | |||
alias pip='pip3' | |||
alias python='python3' | |||
export PATH=$PATH:~/tsh:/home/qlzq/.local/bin | |||
export STARDICT_DATA_DIR=/home/qlzq/Documents/En | |||
if [ -f ~/.Xmodmap ]; then xmodmap ~/.Xmodmap; fi | |||
# # Install Ruby Gems to ~/gems | |||
# export GEM_HOME="$HOME/gems" | |||
# export PATH="$HOME/gems/bin:$PATH" | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# .Xmodmap | |||
# 把右 Windows 键改为右 Ctrl 键 | |||
clear Mod4 | |||
keycode 134 = Control_R | |||
add control = Control_L Control_R | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# 放进 .bashrc | |||
# 实现黄字 user@server,以区分 server 和 local | |||
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# 显示手动安装的 .deb 包 | |||
apt list --installed | grep "local]" | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" line> | |||
# 当你发现Emacs因为GPG密匙过期,已经无法更新package时应该怎么做 | |||
手动到 GNU ELPA - gnu-elpa-keyring-update 下载 gnu-elpa-keyring-update | |||
在 Emacs 里打开这个 tar 文件,执行 package-install-from-buffer | |||
</syntaxhighlight> |
Latest revision as of 15:31, 3 August 2024
某一天,你拿到了一台新电脑。或者,某一天,你的电脑系统崩溃了。你需要从头配置一套从前习惯的工具链,那么,以下这些小代码,非常有用。请在你理解用处、并自担风险的情况下使用。
Windows 平台
# set-network-private.ps1
# 用于把公用网络改为私用网络,实现全屋共享。需以管理员权限运行:创建快捷方式,目标选本文件
Set-NetConnectionProfile -InterfaceAlias "以太网" -NetworkCategory Private
# shutdown.bat
# 用于双击立即关机,省下从开始键点好几下才关机的工夫
@echo off
shutdown.exe /s /t 00
# 右键创建快捷方式
# 在桌面双击就可以直达知乎
"C:\Program Files\Mozilla Firefox\firefox.exe" https://www.zhihu.com
Debian 平台
#!/bin/bash
# 用于查找本目录下的文件,不区分文件名大小写。包含查找的关键字就可以查到。不想换行该怎么写呢?其实用变量参数$1即可,但两行更方便,符合直觉
read text
find . -iname "*$text*"
#!/bin/bash
# 用于比较文件 hash 值,确认文件是否为原版无更改
echo "input origin > "
read origin
echo "input local > "
read local
if [ ${origin,,} = ${local,,} ]; then
echo "相等"
else
echo "有问题"
fi
#!/bin/bash
# 用于把在电脑上修改过的 rime 配置文件,推送到手机上,并自动重新部署手机端同文输入法
adb shell ime disable com.osfans.trime/.TrimeImeService
adb shell am force-stop com.osfans.trime
adb shell rm -r /sdcard/rime
adb shell mkdir /sdcard/rime
adb push /home/qlzq/500/Code/ok-trime/* /sdcard/rime
adb shell ime enable com.osfans.trime/.TrimeImeService
adb shell ime set com.osfans.trime/.TrimeImeService
adb shell am broadcast -a com.osfans.trime.deploy
#!/bin/bash
# 用于把电脑上的文件快速传到手机上的 01 文件夹
adb push $1 /sdcard/01
# .bashrc
# 好用的 .bashrc 配置
# server
alias s='ls -hl --ignore={Desktop,Documents,Music,Pictures,Public,Templates,Videos}'
alias e='emacs --eval "(load-theme (quote adwaita))"'
alias eq='emacs -Q --eval "(load-theme (quote adwaita))"'
alias eb='emacs -Q --eval "(load-theme (quote adwaita))" /home/$USER/.bashrc'
alias se='sudo emacs -Q --eval "(load-theme (quote adwaita))"'
alias gwk='sudo emacs -Q --eval "(load-theme (quote adwaita))" /etc/mediawiki/LocalSettings.php'
alias sb='source /home/$USER/.bashrc'
alias as='apt search --names-only'
alias ai='sudo apt install'
alias au='sudo apt update'
alias gc='git clone'
alias rmd='rm -rf'
eval "$(lua /home/$USER/Sources/z.lua/z.lua --init bash enhanced once)"
# gui
alias bye='systemctl suspend'
alias sr='systemctl reboot'
alias sp='systemctl poweroff'
alias f='f.sh'
alias gfw='gfw.sh'
alias ff='firefox-esr -p >>/dev/null 2>&1 &'
alias nl='firefox-esr -p Offline $1'
alias sj='scrcpy -S >>/dev/null 2>&1 &'
alias a2sj='a2sj.sh'
alias gt='./gt.sh'
alias p3='python3'
alias tl='sudo tldr'
alias pip='pip3'
alias python='python3'
export PATH=$PATH:~/tsh:/home/qlzq/.local/bin
export STARDICT_DATA_DIR=/home/qlzq/Documents/En
if [ -f ~/.Xmodmap ]; then xmodmap ~/.Xmodmap; fi
# # Install Ruby Gems to ~/gems
# export GEM_HOME="$HOME/gems"
# export PATH="$HOME/gems/bin:$PATH"
# .Xmodmap
# 把右 Windows 键改为右 Ctrl 键
clear Mod4
keycode 134 = Control_R
add control = Control_L Control_R
# 放进 .bashrc
# 实现黄字 user@server,以区分 server 和 local
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# 显示手动安装的 .deb 包
apt list --installed | grep "local]"
# 当你发现Emacs因为GPG密匙过期,已经无法更新package时应该怎么做
手动到 GNU ELPA - gnu-elpa-keyring-update 下载 gnu-elpa-keyring-update
在 Emacs 里打开这个 tar 文件,执行 package-install-from-buffer