thn【script-hexo新建博客并且使用typora打开】

环境

  • macos
    • 14.2.1 (23C71)
  • 版本
    • mac M1
  • 使用条件
    • 安装了typora
    • 配置脚本中hexo的地址

脚本作用

使用hexo创建的脚本放在_post底下,编辑什么的都不太方便,个人平常习惯使用typora写markdown,所以就有了这个脚本,这个脚本的作用是帮助你创建新博客的同时使用typora打开这个博客并且进行编辑。

使用效果

1、查询当前的blog文章 thn -ls

image-20240228113158010

2、thn $(thn -ls | grep scrip) 或者更简单的 thn -ls | grep thn | thn

直接使用typora打开文档并且进行编辑

image-20240228113057067

3、 thn temp

创建文档

image-20240228113428932

脚本定义

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
#!/bin/bash

post_title=""
if [ ! -t 0 ]; then
# 检测到数据来自管道
while IFS= read -r line; do
# 处理每行输入
post_title="$line"
echo "处理: $line"
# 您的逻辑代码
done
else
# 检查是否提供了必需的参数
if [ -z "$1" ]; then
echo "Usage: $0 <post_title>"
exit 1
fi
post_title="$1"
fi


# 如果传入 --ls 参数,则输出指定路径下的所有文件列表
if [ "$1" = "-ls" ]; then
ls /Users/xxxx/IdeaProjects/blog/source/_posts/
exit 0
fi
# 提取命令行参数中的文章标题

post_title=${post_title%.md}
echo "$post_title"
# 指定文章存放路径
post_path="/Users/xxxx/IdeaProjects/blog/source/_posts/${post_title}.md"

# 检查文件是否已经存在
if [ -e "$post_path" ]; then
echo "File '$post_path' already exists. Skipping Step 1."

# 直接执行 Step 2
typo_command="open -a typora '$post_path'"
typo_output=$(eval "$typo_command")

echo "Step 2 Output:"
echo "$typo_output"

exit 0
fi

# Step 1: hexo new 命令
hexo_new_output=$(hexo new "$post_title")

# 提取 hexo new 输出中的路径
post_path=$(echo "$hexo_new_output" | grep "Created:" | awk '{print $3}')
echo "$post_path"

# Step 2: typo 命令
typo_command="open -a typora $post_path"
typo_output=$(eval "$typo_command")

echo "Step 1 Output:"
echo "$hexo_new_output"

echo "Step 2 Output:"
echo "$typo_output"


#!/bin/bash

# 检查是否提供了必需的参数
if [ -z "$1" ]; then
echo "Usage: $0 <post_title>"
exit 1
fi

# 如果传入 --ls 参数,则输出指定路径下的所有文件列表
if [ "$1" = "-ls" ]; then
ls /Users/xxxx/IdeaProjects/blog/source/_posts/
exit 0
fi
# 提取命令行参数中的文章标题
post_title="$1"
post_title=${post_title%.md}
echo "$post_title"
# 指定文章存放路径
post_path="/Users/xxxx/IdeaProjects/blog/source/_posts/${post_title}.md"

# 检查文件是否已经存在
if [ -e "$post_path" ]; then
echo "File '$post_path' already exists. Skipping Step 1."

# 直接执行 Step 2
typo_command="open -a typora $post_path"
typo_output=$(eval "$typo_command")

echo "Step 2 Output:"
echo "$typo_output"

exit 0
fi

# Step 1: hexo new 命令
hexo_new_output=$(hexo new "$post_title")

# 提取 hexo new 输出中的路径
post_path=$(echo "$hexo_new_output" | grep "Created:" | awk '{print $3}')
echo "$post_path"

# Step 2: typo 命令
typo_command="open -a typora $post_path"
typo_output=$(eval "$typo_command")

echo "Step 1 Output:"
echo "$hexo_new_output"

echo "Step 2 Output:"
echo "$typo_output"


thn【script-hexo新建博客并且使用typora打开】
http://orikey0.github.io/2024/01/28/【thn】(script-hexo新建博客并且使用typora打开)/
作者
Howard Lee
发布于
2024年1月28日
许可协议