#!/bin/bash
# Initial variables; the last underscore in $PROFILE_NAME_TEMPLATE is important
BOOKMARKS_DIR="$HOME/.config/gtk-3.0"
BOOKMARKS="$BOOKMARKS_DIR/bookmarks"
PROFILES_DIR="$BOOKMARKS_DIR/bookmarks_profiles"
PROFILE_NAME_TEMPLATE="$PROFILES_DIR/bookmarks_profile_"
# If the profiles directory doesn't exist create it,
# otherwise renumber the existing profiles in case some of them were deleted
[[ ! -d $PROFILES_DIR ]] && mkdir -p "$PROFILES_DIR" || rename 's/[0-9]*$/our $i; sprintf("%d", 1+$i++)/e' "$PROFILES_DIR/"*
# Get the list of the profiles as an array,
# the expression `[[ -z ${PROFILES[@]##*\*} ]]` means `if the directory is empty` or not empty when there is a `!`
PROFILES=("$BOOKMARKS_DIR/bookmarks_profiles/"*)
main() {
# Compare the current profile to each existing profile in $PROFILES and find the $CURRENT_PROFILE if it exists
for profile in "${PROFILES[@]}"; do cmp -s "$BOOKMARKS" "$profile" && CURRENT_PROFILE="$profile"; done
# Get the number of the current profile
CURRENT_PROFILE_NUMBER="${CURRENT_PROFILE##*_}"
# If the $CURRENT_PROFILE doesn't exist in the list of profiles and the directory is epty: $NEW_PROFILE_NUMBER = 1
# If it doesn't exist and the directory is not epty: $NEW_PROFILE_NUMBER = ( number of the profiles + 1 )
# If this is the last profile from the list the next profile number is 1: $NEW_PROFILE_NUMBER = 1
# In all other case increment the $CURRENT_PROFILE_NUMBER by 1
if [[ -z ${CURRENT_PROFILE+x} && -z ${PROFILES[@]##*\*} ]]; then
NEW_PROFILE_NUMBER=1
elif [[ -z ${CURRENT_PROFILE+x} && ! -z ${PROFILES[@]##*\*} ]]; then
NEW_PROFILE_NUMBER=$(( ${#PROFILES[@]} + 1 ))
elif [[ $CURRENT_PROFILE_NUMBER -eq ${PROFILES[-1]##*_} ]]; then
NEW_PROFILE_NUMBER=1
else
NEW_PROFILE_NUMBER=$(( CURRENT_PROFILE_NUMBER + 1 ))
fi
# If the current profile doesn't exist in the list add it, else just switch to the next profile
if [[ -z ${CURRENT_PROFILE+x} ]]; then
cp "${BOOKMARKS}" "${PROFILE_NAME_TEMPLATE}${NEW_PROFILE_NUMBER}"
echo "Profile ${NEW_PROFILE_NUMBER} is CREATED"
else
cp "${PROFILE_NAME_TEMPLATE}${NEW_PROFILE_NUMBER}" "${BOOKMARKS}"
echo "Profile ${NEW_PROFILE_NUMBER} is ACTIVATED"
fi
}
killall notify-osd >/dev/null 2>&1 # Kill all notify-send messages
notify-send "$(main 2>&1)" # Call the `main` function and output all messages through `notify-send`
我发现 Nautilus 书签在文件内容更改时会动态
~/.config/gtk-3.0/bookmarks
更改。所以我的建议是下面的脚本,可以绑定到自定义键盘快捷键。这是它的工作原理:创建可执行文件,调用
nautilus-bookmarks-manager
并位于/usr/local/bin
可作为 shell 命令访问的目录中(或使用不同的名称和位置):在命令应位于的位置创建自定义键盘快捷键:
脚本内容为:
该脚本会将每个新配置文件存储在目录中
~/.config/gtk-3.0/bookmarks_profiles
。如果此目录不存在,则会创建它。否则,脚本将尝试重新分配现有配置文件,以防您删除了其中一些配置文件。这导致两种情况:下一个。该脚本会将文件
~/.config/gtk-3.0/bookmarks
与~/.config/gtk-3.0/bookmarks_profiles
. 如果发现巧合,脚本将切换到下一个配置文件。如果没有巧合,将创建一个新的配置文件。脚本的更高级版本可以使用命名(而不是编号)配置文件和一些工具(如zenity )来获取新配置文件的名称。