-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
149 lines (123 loc) · 4.21 KB
/
.bashrc
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Sample .bashrc for SuSE Linux
# Copyright (c) SuSE GmbH Nuernberg
# There are 3 different types of shells in bash: the login shell, normal shell
# and interactive shell. Login shells read ~/.profile and interactive shells
# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all
# settings made here will also take effect in a login shell.
#
# NOTE: It is recommended to make language settings in ~/.profile rather than
# here, since multilingual X sessions would not work properly if LANG is over-
# ridden in every subshell.
# Some applications read the EDITOR variable to determine your favourite text
# editor. So uncomment the line below and enter the editor of your choice :-)
#export EDITOR=/usr/bin/vim
#export EDITOR=/usr/bin/mcedit
# For some news readers it makes sense to specify the NEWSSERVER variable here
#export NEWSSERVER=your.news.server
# If you want to use a Palm device with Linux, uncomment the two lines below.
# For some (older) Palm Pilots, you might need to set a lower baud rate
# e.g. 57600 or 38400; lowest is 9600 (very slow!)
#
#export PILOTPORT=/dev/pilot
#export PILOTRATE=115200
test -s ~/.alias && . ~/.alias || true
# osc config
export COMP_WORDBREAKS=${COMP_WORDBREAKS/:/}
# PATH Config
export PATH=$HOME/.local/bin:$PATH
# Start neofetch
/usr/bin/neofetch
# Load user completion statement
# source $HOME/.local/share/bash-completion/completions/*
############################# 回收站配置 ######################################
# 依赖 https://github.com/andreafrancia/trash-cli
# 依赖 autotrash
# 安装 pip3 install trash-cli
# 安装 zypper install autotrash
# 配置 autotrash -T ~/.local/share/trash -d 3 --install # -d 表示自动清除?天前的文件
# 配置 systemctl --user enable autotrash.timer
# 以下替换rm操作仅在用户操作,shell脚本不受影响
###############################################################################
# 回收站存放目录
export TRASH_CAN=$HOME/.local/share/trash
if [ ! -d "$TRASH_CAN" ]; then
mkdir -p $TRASH_CAN
fi
# 修改默认目录
alias trash-list="trash-list --trash-dir $TRASH_CAN"
alias trash-empty="trash-empty --trash-dir $TRASH_CAN"
alias trash-put="trash-put --trash-dir $TRASH_CAN"
# 更改trash补全声明为rm
eval "$(trash --print-completion bash)"
complete -F _shtab_trash rm
rpl_rm(){
OPTS=""
FILE=""
LINK=""
DIR=""
ONLY_OPTS=true
REMOVE_DIR=false
REMOVE_EMPTY_DIR=false
# 解析操作符
for ((index=1;index<=$#; index++))
do
if [[ "${!index}" == -* ]]; then
OPTS="$OPTS ${!index}"
# 如果有递归删除的操作符
# 将RM_DIR变量设置为true
if [[ "${!index}" =~ ^-[a-zA-Z]*[rR]|^--recursive$ ]]; then
REMOVE_DIR=true
# 是否启用删除空目录选项
elif [[ "${!index}" =~ ^-[a-zA-Z]*d|^--dir$|^--directory$ ]]; then
REMOVE_EMPTY_DIR=true
fi
else
ONLY_OPTS=false
shift $[index-1]
break
fi
done
if [[ $ONLY_OPTS == true ]]; then
# shift $[index-1]
trash $OPTS
return
fi
for ((index=1;index<=$#; index++))
do
if [ -L "${!index}" ]; then
LINK="$LINK ${!index}"
elif [ -f "${!index}" ]; then
FILE="$FILE ${!index}"
elif [ -d "${!index}" ]; then
DIR="$DIR ${!index}"
else
echo "${!index} 不存在" >&2
fi
done
# 启用递归删除
if [[ $REMOVE_DIR == true ]]; then
trash $OPTS --trash-dir=$TRASH_CAN $FILE $DIR
return
# 未启用递归删除
else
if [ ! -z "$FILE" ]; then
trash $OPTS --trash-dir=$TRASH_CAN $FILE
fi
if [ ! -z "$DIR" ]; then
# 启用删除空目录
if [[ $REMOVE_EMPTY_DIR == true ]]; then
rm -d $DIR
else
rm -i $DIR
fi
fi
if [ ! -z "$LINK" ]; then
trash -i $OPTS --trash-dir=$TRASH_CAN $LINK
fi
return
fi
}
if [[ $0 == /bin/bash ]]; then
alias rm=rpl_rm
fi
############################# 回收站配置 ######################################